coordiante.h
class coordinate
{
public:
coordinate(int x, int y);
~coordinate();
int getx();
int gety();
public:
int m_ix;
int m_iy;
};
coordinate.cpp
#include"coordinate.h"
#include<iostream>
using namespace std;
coordinate::coordinate(int x, int y)
{
m_ix = x;
m_iy = y;
cout << "(" << m_ix << "," << m_iy << ")" << endl;
}
coordinate::~coordinate()
{
cout << "我是析构函数" << endl;
}
int coordinate::getx()
{
return m_ix;
}
line.h
#include"coordinate.h"
class line
{
line(int x1, int y1, int x2, int y2);
~line();
void printinfo();
private:
coordinate *m_pcoora;
coordinate *m_pcoorb;
};
line.cpp
#include"line.h"
#include<iostream>
using namespace std;
line::line(int x1, int y1, int x2, int y2)
{
m_pcoora = new coordinate(x1, y1);
m_pcoorb = new coordinate(x2, y2);
cout << "line" << endl;
}
line::~line()
{
delete m_pcoora;
m_pcoora = NULL;
delete m_pcoorb;
m_pcoorb = NULL;
cout << "~line" << endl;
}
void line::printinfo()
{
cout << "(" << m_pcoora->getx() << "," << m_pcoora->gety() << ")" << endl;
cout << "(" << m_pcoorb->getx() << "," << m_pcoorb->gety << ")" << endl;
}
main.cpp
#include<iostream>
#include"line.h"
using namespace std;
int main()
{
line *p = new line(1, 2, 3, 4);
delete p;
p = NULL;
system("pause");
return 0;
}
出现的错误:
严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E0330 "line::line(int x1, int y1, int x2, int y2)" (已声明 所在行数:6,所属文件:"E:\VS-c++\thispoint\thispoint\line.h") 不可访问 thispoint E:\VS-c++\thispoint\thispoint\main.cpp 8
严重性 代码 说明 项目 文件 行 禁止显示状态
错误(活动) E0330 "line::~line()" (已声明 所在行数:7,所属文件:"E:\VS-c++\thispoint\thispoint\line.h") 不可访问 thispoint E:\VS-c++\thispoint\thispoint\main.cpp 10
严重性 代码 说明 项目 文件 行 禁止显示状态
错误 C3867 “coordinate::gety”: 非标准语法;请使用 "&" 来创建指向成员的指针 thispoint e:\vs-c++\thispoint\thispoint\linecpp.cpp 25
相关分类