可能重复:
对 vtable 的未定义引用
运行以下代码会导致链接器错误
'undefined reference to vtable for ManagedObjects'
#include <cstdlib>
#include <iostream>
#include <list>
#include <string>
using namespace std;
class ManagedObjects
{
public:
virtual string get() const;
virtual ~ManagedObjects(){};
};
class CallbackOwner1 : public ManagedObjects
{
public:
string get() const {return "CallbackOwner1";}
};
class CallbackFunctor
{
public:
CallbackFunctor(const ManagedObjects* b):m_cbr(b)
{}
string operator() ()
{
return m_cbr->get();
}
const ManagedObjects* m_cbr;
};
int main(int argc, char *argv[])
{
ManagedObjects* cb1 = new CallbackOwner1();
CallbackFunctor f(cb1);
cout << f() << endl;
system("PAUSE");
return EXIT_SUCCESS;
}