You are not logged in.
Pages: 1
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
[edit] Sorry, double post.
Last edited by snack (2009-11-04 14:49:04)
Offline
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
hehe, cool.
You can mark your thread as 'Solved' if you solved it.
Offline
hehe, cool.
You can mark your thread as 'Solved' if you solved it.
Actually, it is...
Offline
Pages: 1