构造函数对类私有成员变量默认初始化

#include <iostream>
using namespace std;
class point
{
  public:
  point():x(10),y(20) {

  }

  void outxy(void);
  void setxy(int ,int);
  private:
  int x;
  int y;
};

void point::outxy(void)
{
  cout <<"x = "<<x<<" y = "<<y<<endl;
}
void point::setxy(int x,int y)
{
  this->x = x;
  this->y = y;
}
int main(int argc, char *argv[])
{
  point x;

  x.outxy();
  x.setxy(2,4);
  x.outxy();
  return 0;;
}

 

posted @ 2019-01-17 16:36  小小小笨蛋  阅读(960)  评论(0编辑  收藏  举报