undefined reference to `vtable for

池塘的蜗牛 2013-04-12 04:39:49
linux下编程时出现: undefined reference to `vtable for .....
源程序:
***************************** main.c****************
#include<iostream>
#include"C++.h"
#define Debug

using std::cout;
using std::cin;
using std::endl;

int main()
{
otherClass *p;
p = new otherClass;
p->print();
return 0;
}
*************************C++.h*************************

#ifndef sh_h
#define sh_h
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

class myClass{
public:
virtual void print() = 0;
private:
int myInt;
};

class otherClass : public myClass{
public:
otherClass():otherInt(0){}
~otherClass(){}
virtual void print();
private:
int otherInt;
};

#endif
***********************C++.c****************************8
#include<iostream>
#include"C++.h"
using namespace std;

void otherClass :: print()
{
cout<<"construct all";
}
**************************makefile*********************
edit: main.o sh.o
g++ -o edit main.o sh.o

main.o: main.cpp C++.h
g++ -o main.o main.cpp
sh.o: C++.cpp C++.h
g++ -o sh.o C++.cpp
.PHONY:clean
clean:
rm *.o
***********************************************************8888
当make时出现 undefined reference to `vtable for ...
主要是说我的虚函数没有实现,但是我在C++.c中已经实现:
最后我在makefile中cpp前加上-c后问题得以解决,但是不知为什么,请大神指导






...全文
114 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
池塘的蜗牛 2013-04-13
  • 打赏
  • 举报
回复
文件名都是cpp
www_adintr_com 2013-04-12
  • 打赏
  • 举报
回复
你文件名是 main.cpp 还是 main.c ? makefile 里的和你上面说的不一样.

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧