zmact60@doc.ic.ac.uk (I S Roberts) (06/13/90)
What (if any) difference does the ordering of the base classes for
a derived class make?
eg, How could
class A : public B, public C {...
be different from
class A : public C, public B {...
B and C have pure virtual functions, but all function names are unqiue.
I am using a fairly complex class structure with multiple inheritance
to implement an extened syntax tree for a program. I am using g++
1.37.0. With the base classes in one order the program works fine.
Reverse the order of the base classes and I either get compilation
errors or (apparently) wrong virtual functions called.
Any suggestions?
Ian.zmact60@doc.ic.ac.uk (I S Roberts) (06/13/90)
Further to my previous posting, with a little help from Duncan White I
have isolated the problem. Try compiling the following code;
1) As is,
2) With the comment commenting out the line after the one that is
already commented out, removing the // that is alrady there (Phew...)
Anyway, you get the idea,
As is g++ (1.37.0) compiles it OK,
after (2) I get
g++ -c t.cc
t.cc: In function int main ():
t.cc:25: cannot allocate an object of type `Category'
t.cc:25: since the following virtual functions are abstract:
t.cc:4: void Dependant::Perform (int)
------------------------- cut here ----------------------
class Dependant {
public:
virtual void Perform(int) = 0 ;
} ;
class ReferenceCounter : public Dependant {
public:
virtual void Perform(int) = 0 ;
} ;
class DatabaseObj {
public:
virtual void rootDb() { } ;
} ;
//class Category : public DatabaseObj, public ReferenceCounter {
class Category : public ReferenceCounter, public DatabaseObj {
public:
virtual void Perform(int) ;
} ;
main()
{
Category* bar = new Category() ;
}
-------------------- cut again ------------------------------
Ian.
#include Disclaimer.