As an ex-C programmer moving to C++, I imagined this to be an FAQ, but
it isn't:
I have a class whose member functions are implemented in multiple
compilation
unit's (.o). Now, while linking my main program with these .o's, I can
exclude from
the link line all those .o's whose member functions are not called by
the main
program.
Except for virtual member functions, even if my main program never
calls them, I
have to include the corresponding .o's, or else, I get unsatisified
symbols for them
which I imagine are coming from the VTABLE.
What's the C++ way to fix this (multiple inheritance ?)
The C way is to just stub them out!
class Atom {
public:
const char *foo();
virtual const char *bar();
};
class HAtom : public Atom {
public:
const char *bar();
};
Atom::foo is defined in atom1.o. HAtom::bar and Atom::bar are defined
in atom2.o.
But I am forced to link in atom2.o even if my main never calls bar().
If bar() wasn't
virtual, I can get away.
Sincerely,
Kapil