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后问题得以解决,但是不知为什么,请大神指导