|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
具体问题:
定义Chess基类,设置虚析构
编译错误显示如下:
undefined reference to `vtable for Chess'
[Error] ld returned 1 exit status
代码如下:
class Chess
{
private:
int id;
char* name;
public:
Chess(int i,char*n)
{
id = i;
name = new char[2];
strcpy(name,n);
}
virtual ~Chess()
{
delete name;
}
virtual bool judgeMove(Board &b,int startx,int starty,int afterx,int aftery);
};
自我感觉析构已经定义清楚了,但就是不成功,求大佬帮帮我
- #include <iostream>
- #include<cmath>
- #include<cstring>
- using namespace std;
- class Board;
- class Chess
- {
- private:
- int id;
- char* name;
- public:
- //Chess(int i,char*n)
- Chess(int i, const char *n)
- {
- id = i;
- name = new char[2];
- strcpy(name,n);
- }
- virtual ~Chess()
- {
- delete name;
- }
-
- int getId()
- {
- return id;
- }
- void print()
- {
- cout <<name;
- }
- virtual bool judgeMove(Board &b,int startx,int starty,int afterx,int aftery) {return false;}
- };
- class C:public Chess
- {
- public:
- //C(int i,char* n):Chess(i,n) {}
- C(int i, const char *n):Chess(i,n) {}
- ~C()
- {
- cout <<"please";
- }
- void show()
- {
- cout <<"please";
- }
- virtual bool judgeMove(Board &b,int startx,int starty,int afterx,int aftery) {return false;}
- };
- int main()
- {
- C c1(1,"xiang");
- c1.show();
- return 0;
- }
复制代码
|
|