代码
class Test
{
private:
int x, y;
public:
void setX(int a)
{
x=a;
}
void setY(int b)
{
y=b;
}
void printXY(void)
{
cout<<"x="<<x<<'\t'<<"y="<<y<<endl;
}
} ;
int main()
{
Test p1;
p1.setX(3);
p1.setY(5);
p1.printXY( );
return 0;
}
总结:私有成员不能被外界调用,只能通过公有函数来为它们赋值