亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我在VScommunity2017上編寫的程序無法運行?但是程序可以在2015上面運行?

1、'Coordinate': is not a class or namespace name

2、~Coordinate': destructor tag mismatch

......等諸多問題

正在回答

2 回答

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


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

代碼貼出來

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

舉報

0/150
提交
取消
C++遠征之封裝篇(下)
  • 參與學習       70902    人
  • 解答問題       534    個

封裝--面向對象三大特征之一,通過案例讓C++所學知識融會貫通

進入課程

為什么我在VScommunity2017上編寫的程序無法運行?但是程序可以在2015上面運行?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號