 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
kdotk Guest
|
Posted: Fri Jun 16, 2006 9:10 am Post subject: want to leave virtual functions undefined |
|
|
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 |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Fri Jun 16, 2006 9:10 am Post subject: Re: want to leave virtual functions undefined |
|
|
* kdotk:
| Quote: |
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 ?)
|
Basically it's Quality Of Implementation issue: your compiler & linker
should have some option to remove unused definitions.
If you have declared a virtual function in a class, you must also
implement it for that class, except if it's pure virtual (in which case
you cannot instantiate the class, so that's not what you want).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|