You are not logged in.

#1 2009-11-04 14:47:59

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

[SOLVED] vtable error in C++

Hi, I'm facing a fairly common problem iin C++. I have this concrete child of an abstract class:

class TreeOutputAction: public CollectionAction {
public:
  TreeOutputAction(const char *actionName, const char *outFileName) :
  CollectionAction(actionName), _outFileName(outFileName) {
}
  ~TreeOutputAction() { }
  void Setup(PamLevel2 *events);
  void OnGood(PamLevel2 *event);
  void Finalize();

private:

  TFile _outFile;
  const char *_outFileName;
};

All the methods are overrides of virtual methods in the base class CollectionAction. Setup and Finalize are pure virtual in CollectionAction. The implementation in the cpp file is:

#include "TreeOutputAction.h"

void TreeOutputAction::Setup(PamLevel2 *events) {
  _outFile.Open(_outFileName, "RECREATE");
}

void TreeOutputAction::OnGood(PamLevel2 *event) {
  _outFile.cd();
}

void TreeOutputAction::Finalize() {
  _outFile.Write();
  _outFile.Close();
}

When I use my class in a program, the linker gets angry:
     TreeOutputAction.h:33: undefined reference to `vtable for TreeOutputAction'
I searched the web for this and I found that gcc puts the vtable in the object file where the first out-of-line, non-pure virtual function is defined. In my example Setup is out-of-line and non-pure virtual (although it is virtual), so I would expect that the vtable would be put in the object file that contains it. This object file is correctly assembled into a shared library which is then linked to the main program, but the problem happens, indeed.
Where am I wrong? Thanks for the help.

Last edited by snack (2009-11-05 00:22:36)

Offline

#2 2009-11-04 14:48:32

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] vtable error in C++

[edit] Sorry, double post.

Last edited by snack (2009-11-04 14:49:04)

Offline

#3 2009-11-05 00:22:07

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] vtable error in C++

I solved it, it was a problem in my LD_LIBRARY_PATH which made me linking against an old version of my library. Sorry for the stupid question...

Offline

#4 2009-11-06 21:30:37

djszapi
Member
From: Cambridge, United Kingdom
Registered: 2009-06-14
Posts: 1,439
Website

Re: [SOLVED] vtable error in C++

hehe, cool.

You can mark your thread as 'Solved' if you solved it.

Offline

#5 2009-11-07 11:00:02

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 876

Re: [SOLVED] vtable error in C++

djszapi wrote:

hehe, cool.

You can mark your thread as 'Solved' if you solved it.

Actually, it is... wink

Offline

Board footer

Powered by FluxBB