473,322 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

Jun 16 '06 #1
1 1602
* kdotk:

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?
Jun 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: alex.mizrahi | last post by:
helo i'm going to use pointers to member function with virtual inheritance in following way: struct base { public: typedef void (base::*fun_t)(void); int i; void call(fun_t f) {
26
by: pmizzi | last post by:
When i compile my program with the -ansi -Wall -pedantic flags, i get this warning: `class vechile' has virtual functions but non-virtual destructor, and the same with my sub-classes. But when i...
20
by: Daniel | last post by:
I have the following three classes class A { public: virtual void f() = 0; }; class B: public A {
3
by: Pravesh | last post by:
Hello All, I had some query regarding virtual functions/destructors. If a class is having some/all of its methods that are virtual then is it recommended that it should also have virtual...
3
by: trond.norbye | last post by:
Hi I am trying to compile a quite large software system with a new compiler. During that attempt I am facing problems during the link phase, and I have traced it down to the following construct:...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
7
by: eric | last post by:
hello i'm confused by an example in the book "Effective C++ Third Edition" and would be grateful for some help. here's the code: class Person { public: Person(); virtual ~Person(); // see...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
3
by: Rahul | last post by:
Hi Everyone, I have the following polymorphic classes, class Shape { public : virtual void draw() { } virtual void sample();
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.