help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

virtual inheritance difficulties


From: Gav Wood
Subject: virtual inheritance difficulties
Date: Wed, 03 Nov 2004 12:26:46 +0000
User-agent: KNode/0.8.0

> The reason is that two baseclasses could be virtually derived from the
> same base, and both could provide different parameters to their base, so
> that makes no sense - I think every concrete class along the tree has to
> call the virtual base's ctor with proper parameters.

thanks for the advice. i got around it by erasing unneccessary virtual
inheritance.

i have another problem now though:

the code is something like this:

namespace geddei {
class Processor
{
public:
        const Connection* connect(unsigned int, unsigned int, const QString&,
                unsigned int, const QString&, unsigned int);
        const Connection* connect(unsigned int, unsigned int, Sink*,
                unsigned int);
};
        ...
}

class Multiplicative { ... };

class MultiSink : virtual public Multiplicative { ... };

class MultiSource : virtual public Multiplicative
{
public:
        void connect(unsigned int, MultiSink*);
        ...
};

class NProcessor: public geddei::Processor, public MultiSource,
        public MultiSink
{
        ...
};

class TMO: public NProcessor { ... };
class TMI: public NProcessor { ... };

int main()
{
        TMO o;
        TMI i;
        o.connect(1, &i);
}

i get the error:

/home/gav/Projects/geddei/src/tests/testmulti.cpp:427: error: request for
 member `connect' is ambiguous
/home/gav/Projects/geddei/src/tests/testmulti.cpp:245: error: candidates
 are: void MultiSource::connect(unsigned int, MultiSink*)
/home/gav/Projects/geddei/src/geddei/processor.h:404: error: const
 geddei::Connection* geddei::Processor::connect(unsigned int, unsigned int,
 const QString&, unsigned int, const QString&, unsigned int)
/home/gav/Projects/geddei/src/geddei/processor.h:397: error: const
 geddei::Connection* geddei::Processor::connect(unsigned int, unsigned int,
 geddei::Sink*, unsigned int)
*** Exited with status: 2 ***

yes there is no ambiguity - not only are the parameters different types, but
the parameter sets are even different cardinalities!

if i instead specify

        o.MultiSource::connect(1, &i); // rather than o.connect(1, &i);

it works fine.

what can i do to make g++ work as i expect (no ambiguity)? i presume it has
something to do with the inheritance lattice, but i'm not sure how to
remedie it.

cheers,

gav
-- 
York


reply via email to

[Prev in Thread] Current Thread [Next in Thread]