Help! What's wrong with this C++ code ?

Body

Why won't this shit compile ? What's wrong ? I don't get it!

#include <vector>
#include <iostream>

using namespace std;

class foo {
public:
   virtual void write();
};

class fubar : public foo {
public:
  void write() { cout << __PRETTY_FUNCTION__ << endl; }
};

class fubar2 : public foo {
public:
  void write() { cout << __PRETTY_FUNCTION__ << endl; }
};

int main()
{
  vector<foo> v;
  fubar one;
  v.push_back(one);
}

g++ -o foo foo.cc
/tmp/cchSMAqr.o:(.gnu.linkonce.r._ZTI5fubar[typeinfo for fubar]+0x8): undefined reference to `typeinfo for foo'
/tmp/cchSMAqr.o: In function `foo::foo()':foo.cc:(.gnu.linkonce.t._ZN3fooC2Ev[foo::foo()]+0x4): undefined reference to `vtable for foo'
/tmp/cchSMAqr.o: In function `foo::foo(foo const&)':foo.cc:(.gnu.linkonce.t._ZN3fooC1ERKS_[foo::foo(foo const&)]+0x4): undefined reference to `vtable for foo'
/tmp/cchSMAqr.o: In function `foo::~foo()':foo.cc:(.gnu.linkonce.t._ZN3fooD1Ev[foo::~foo()]+0x4): undefined reference to `vtable for foo'
collect2: ld returned 1 exit status

Add new comment

The content of this field is kept private and will not be shown publicly.