?? location.hpp
字號:
#ifndef LOCATION_H #define LOCATION_H #include <iostream> using namespace std; #include <math.h> #include <boost/shared_ptr.hpp> class Location { public: typedef boost::shared_ptr<Location> LocationPtr; Location(); Location(float x, float y, float z); static inline float distance(const Location& loc1, const Location& loc2); inline void setCoordinates(float x, float y, float z); inline float getX() const; inline float getY() const; inline float getZ() const; private: float m_xCoordinate; float m_yCoordinate; float m_zCoordinate; }; typedef boost::shared_ptr<Location> LocationPtr; // Inline Functions inline float Location::distance(const Location& loc1, const Location& loc2) { float xDiff = loc1.getX() - loc2.getX(); float yDiff = loc1.getY() - loc2.getY(); float zDiff = loc1.getZ() - loc2.getZ(); return sqrt(pow(xDiff, 2) + pow(yDiff, 2) + pow(zDiff, 2)); } inline void Location::setCoordinates(float x, float y, float z) { m_xCoordinate = x; m_yCoordinate = y; m_zCoordinate = z; } inline float Location::getX() const { return m_xCoordinate; } inline float Location::getY() const { return m_yCoordinate; } inline float Location::getZ() const { return m_zCoordinate; } // Overloaded Operators inline ostream& operator<< (ostream& s, const Location& location) { return s << "(x=" << location.getX() << ", y=" << location.getY() << ", z=" << location.getZ() << ")"; } #endif // LOCATION_H
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -