Thread View: gnu.g++.bug
1 messages
1 total messages
Started by loepere
Tue, 04 Jul 1989 01:19
multiple inheritance and virtual functions (1.35.1-)
Author: loepere
Date: Tue, 04 Jul 1989 01:19
Date: Tue, 04 Jul 1989 01:19
115 lines
2613 bytes
2613 bytes
If I declare a class to be derived from multiple classes in which more
than one has virtual functions, the resultant object will have more
than one _vtbl entry (one for each class with virtual functions).
Unfortunately, the constructor for the derived class only sets
(changes) the first _vtbl entry, making the other virtual functions
non-virtual. - Keith
#include <stream.h>
class singer
{
public:
singer (const int a_preferred_key);
virtual void sing (ostream &s);
protected:
int preferred_key;
};
inline singer::singer (const int a_preferred_key)
{
preferred_key = a_preferred_key;
}
void singer::sing (ostream &s)
{
s << "La";
for (int i = 0; i < preferred_key; i++)
s << "a";
};
enum dancer_t {ballet, jazz, tap};
class dancer
{
public:
dancer (const dancer_t a_type);
virtual void dance (ostream &s);
protected:
dancer_t type;
};
inline dancer::dancer (const dancer_t a_type)
{
type = a_type;
}
void dancer::dance (ostream &s)
{
switch (type)
{
case ballet:
s << "^v^v^v^v^v^v";
break;
case jazz:
s << "<><><><><><>";
break;
case tap:
s << "............";
break;
}
}
enum cat_t {persian, tabby, siamese};
class performing_cat : public dancer, public singer
{
public:
performing_cat (const cat_t cat_type, const int preferred_key, const dancer_t dance_type);
void sing (ostream &s);
void dance (ostream &s);
protected:
cat_t type;
};
inline performing_cat::performing_cat (const cat_t cat_type, const int preferred_key, const dancer_t dance_type)
: singer (preferred_key), dancer (dance_type)
{
type = cat_type;
}
void performing_cat::sing (ostream &s)
{
s << "Me";
for (int i = 0; i < preferred_key; i++)
s << "e";
for (i = 0; i < preferred_key; i++)
s << "o";
s << "ow";
}
void performing_cat::dance (ostream &s)
{
dancer::dance (s);
s << "(pounce)";
}
int main ()
{
performing_cat morris (tabby, 4, jazz);
singer *one = &morris;
one->sing (cout);
cout << "\n";
dancer *two = &morris;
two->dance (cout);
cout << "\n";
return 0;
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads