#ifndef My_DPoint_h__ #define My_DPoint_h__ #include <math.h>class CDPoint { public: //! The default constructor /*! The default constructor does NOT initialize the vector. This is for efficiency */ CDPoint( ) { } //! Constructor to initialize a vector with (x, y). CDPoint ( float x, float y ) { data[0] = x; data[1] = y; } //! Return a vector whose elements are all zero. static CDPoint Zero ( ) { CDPoint result; result.data[0] = 0; result.data[1] = 0; return result; } //! Return a vector whose elements are all the same and equal to the parameter. static CDPoint Fill( float x ) { CDPoint result; result.data[0] = x; result.data[1] = x; return result; } //! Return the X element of the vector float X( ) const { return data[0]; } //! Return the Y element of the vector float Y( ) const { return data[1]; } //! Return an element of the vector specified by the index /*! Return an element of (*this) specified by index. Elements are indexed [0..1]. It is a programming error to specify an index out of range. */ float Elem( int index ) const { return data[index]; } //! Set an element of the vector specified by the index /*! Set an element of (*this) specified by index. The other two elements are unaffected. Elements are indexed [0..1]. It is a programming error to specify an index out of range. */ void SetElem( int index, float value ) { data[index] = value; } //! Test the equality of this vector and another vector /*! Return true iff (*this) is equal to the other vector according to the built in C/C++ floating point equality operator. */ bool Equals( const CDPoint& other ) const { return ( data[0] == other.data[0] && data[1] == other.data[1] ); } //! Test the equality of this vector and the zero vector /*! Return true iff (*this) is equal to the zero vector according to the built in C/C++ floating point equality operator. */ bool IsZero( ) const { return ( data[0] == 0 && data[1] == 0 ); }private: float data[2]; };#endif
#define My_DPoint_h__
#include <math.h>class CDPoint
{
public: //! The default constructor
/*!
The default constructor does NOT initialize the vector. This is for efficiency
*/
CDPoint(
) {
} //! Constructor to initialize a vector with (x, y).
CDPoint (
float x,
float y
) {
data[0] = x;
data[1] = y;
} //! Return a vector whose elements are all zero.
static CDPoint Zero (
) {
CDPoint result;
result.data[0] = 0;
result.data[1] = 0;
return result;
} //! Return a vector whose elements are all the same and equal to the parameter.
static CDPoint Fill(
float x
) {
CDPoint result;
result.data[0] = x;
result.data[1] = x;
return result;
} //! Return the X element of the vector
float X(
) const {
return data[0];
} //! Return the Y element of the vector
float Y(
) const {
return data[1];
} //! Return an element of the vector specified by the index
/*!
Return an element of (*this) specified by index. Elements are indexed [0..1].
It is a programming error to specify an index out of range.
*/
float Elem(
int index
) const {
return data[index];
} //! Set an element of the vector specified by the index
/*!
Set an element of (*this) specified by index. The other two elements are unaffected.
Elements are indexed [0..1].
It is a programming error to specify an index out of range.
*/
void SetElem(
int index,
float value
) {
data[index] = value;
} //! Test the equality of this vector and another vector
/*!
Return true iff (*this) is equal to the other vector according to the built in C/C++
floating point equality operator.
*/
bool Equals(
const CDPoint& other
) const {
return (
data[0] == other.data[0] &&
data[1] == other.data[1]
);
} //! Test the equality of this vector and the zero vector
/*!
Return true iff (*this) is equal to the zero vector according
to the built in C/C++ floating point equality operator.
*/
bool IsZero(
) const {
return (
data[0] == 0 &&
data[1] == 0
);
}private: float data[2];
};#endif
class CMyPoint
{
public:
CMyPoint();
CMyPoint(const CMyPoint& Point);
~CMyPoint();
CMyPoint& operator=(const CMyPoint& Point);
void operator+(const CMyPoint& Point1);
protected:
private:
double x;
double y;
};CMyPoint::CMyPoint()
{
}CMyPoint::~CMyPoint()
{
}
CMyPoint::CMyPoint(const CMyPoint& Point)
{
this->x=Point.x;
this->y=Point.y;
}
CMyPoint& CMyPoint::operator=(const CMyPoint& Point)
{
this->x=Point.x;
this->y=Point.y;
return *this;
}void CMyPoint::operator+(const CMyPoint& Point1)
{
x=x+Point1.x;
y=y+Point1.y;
}
{
double x;
double y;
}DPOINT;
如果只是绘制图形而言,结构体是比较方便的