为了账号安全,请及时绑定邮箱和手机立即绑定

哪位高人帮忙 看下错不哪了

#include<stdlib.h>

#include<iostream>


using namespace std;

class Coordinate

{

public:

  Coordinate();

  ~Coordinate();

  void setX(int x);

  int getX();

  void setY(int y);

  int getY();

 private:

  int m_iX;

  int m_iY;

};

Coordinate::Coordinate()

{

cout<<"Coordinate"<<endl;

}

Coordinate::~Coordinate()

{

cout<<"~Coordinate"<<endl;

}

void Coordinate::setX(int x)

{

m_iX=x;

}

int Coordinate::getX()

{

return m_iX;

}

void Coordinate::setY(int y)

{

m_iY=y;

}

int Coordinate::getY()

{

return m_iY;

}

class Line

{

public:

Line();

~Line();

void setA(int x,int y);

void setB(int x,int y);

void printInfo();

private:

Coordinate m_coorA;

Coordinate m_coorB;

};

Line::Line()

{

cout<<"Line"<<endl;

}

Line::~Line()

{

cout<<"~Line"<<endl;

}

void Line::setA(int x,int y)

{

m_coorA.setX(x);

m_coorA.setY(y);

}

void Line::setB(int x,int y)

{

m_coorB.setX(x);

m_coorB.setY(y);

}

void Line::printInfo()

{

cout<<"("<<m_coorA.getX()<<","<<m_coorA.getY()<<")"<<endl;

cout<<"("<<m_coorB.getX()<<","<<m_coorB.getY()<<")"<<endl;

}

int main(void)

{

Line*p=new Line();

delete p;

p=NULL;

system("pause");

return 0;

}


正在回答

2 回答

Line*p=new Line();

这里需要有空格吧,如下

Line *p=new Line();


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C++远征之封装篇(下)
  • 参与学习       70930    人
  • 解答问题       514    个

封装--面向对象三大特征之一,通过案例让C++所学知识融会贯通

进入课程

哪位高人帮忙 看下错不哪了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信