如果成员是private代码怎么写呢
private:
int m_iX;
int m_iY;
private:
int m_iX;
int m_iY;
2016-07-29
#include <iostream>
using namespace std;
class Coordinate
{
public:
Coordinate(int x, int y)
{
// 设置X,Y的坐标
m_iX=x;
m_iY=y;
}
// 实现常成员函数
void printInfo() const
{
cout<<"("<<m_iX<<","<<m_iY<<")"<<endl;
}
private:
int m_iX;
int m_iY;
};
int main(void)
{
const Coordinate coor(3, 5);
// 创建常指针p
const Coordinate* p=&coor;
// 创建常引用c
const Coordinate& c=coor;
coor.printInfo();
p->printInfo();
c.printInfo();
return 0;
}
举报