Multiple Inheritance question
-
I have a base interface called IBFace. From IBFace, I have derived a base implementation class called CBFace. I then declare a new interface called IBFace2, which derives from IBFace. And finally, I wish to create a class that uses the base class CBFace implementation, but also derives from IBFace2 to allow me to supply the implementation. Lets call this final class CBFinalFace. So the inheritance tree looks as follows: IBFace - CBFace --------- - IBFace2 | -----------> CBFinalFace When I compile (with all the pure abstract functions implemented), I receive the C4259 warning that "pure virtual function was not defined". The functions it lists are all the functions from IBFace. How do I get past this? It seems that even though CBFace implements all the functions, the fact that I derive from CBFace and then again from IBFace2 (which also derives from IBFace), I get the problem. any ideas?
-
I have a base interface called IBFace. From IBFace, I have derived a base implementation class called CBFace. I then declare a new interface called IBFace2, which derives from IBFace. And finally, I wish to create a class that uses the base class CBFace implementation, but also derives from IBFace2 to allow me to supply the implementation. Lets call this final class CBFinalFace. So the inheritance tree looks as follows: IBFace - CBFace --------- - IBFace2 | -----------> CBFinalFace When I compile (with all the pure abstract functions implemented), I receive the C4259 warning that "pure virtual function was not defined". The functions it lists are all the functions from IBFace. How do I get past this? It seems that even though CBFace implements all the functions, the fact that I derive from CBFace and then again from IBFace2 (which also derives from IBFace), I get the problem. any ideas?
If I understand your problem correctly, I think you are expecting
CBFinalFace
to inherit the functionality implemented inIBFace
by theCBFace
class. This is not possible in COM, you can only inherit the actual interface. You will have to implement functions inCBFinalFace
for yourIBFace2
interface and yourIBFace
interface. Incidentally, you'd have been better off posting this in the COM forum. "Oh, I'm sick of doing Japanese stuff! In jail we had to be in this dumb kabuki play about the 47 Ronin, and I wanted to be Oshi, but they made me Ori!" -
If I understand your problem correctly, I think you are expecting
CBFinalFace
to inherit the functionality implemented inIBFace
by theCBFace
class. This is not possible in COM, you can only inherit the actual interface. You will have to implement functions inCBFinalFace
for yourIBFace2
interface and yourIBFace
interface. Incidentally, you'd have been better off posting this in the COM forum. "Oh, I'm sick of doing Japanese stuff! In jail we had to be in this dumb kabuki play about the 47 Ronin, and I wanted to be Oshi, but they made me Ori!"Actually, I'm not using COM at all. Sorry if the word interface mislead you. Yes, I know that in COM you cannot have implementation inheritance. But what I was doing was in straight, raw C++... no M$ or middleware involved. so, interface can be read as struct i.e: struct I1 { virtual void fn() = 0; }; struct I2 : public I1 {}; class C1 :public I1 { void fn(); }; class C2 : public C1, public I2 {}; hope this clarifies my query a bit more :)
-
Actually, I'm not using COM at all. Sorry if the word interface mislead you. Yes, I know that in COM you cannot have implementation inheritance. But what I was doing was in straight, raw C++... no M$ or middleware involved. so, interface can be read as struct i.e: struct I1 { virtual void fn() = 0; }; struct I2 : public I1 {}; class C1 :public I1 { void fn(); }; class C2 : public C1, public I2 {}; hope this clarifies my query a bit more :)
I am not a C++ guru, but this is how I understand the problem. You have a diamond pattern:
I1 / \ I2 C1 \ / C2 I1::f=0 I2 f=? C1 f={} C2 ( f = I2::f or C1::f ? )
which you should always try to avoid when you use multiple inheritance. BTW: many people complain about multiple inheritance, but as long as you avoid a diamond patter, you'll be fine. So C2 is asking which f() should I make visible ? Your answer is: the one implemented. But this you know it only at linkage time. You need to implement f also in I2 and still you'll get an error because you still didn't answer the question ( f = I2::f or C1::f ? ) So you need to implement C2::f() { return C1::f(); } or you need to delete the declaration of f() in I1 Hope it clarifies. -
I have a base interface called IBFace. From IBFace, I have derived a base implementation class called CBFace. I then declare a new interface called IBFace2, which derives from IBFace. And finally, I wish to create a class that uses the base class CBFace implementation, but also derives from IBFace2 to allow me to supply the implementation. Lets call this final class CBFinalFace. So the inheritance tree looks as follows: IBFace - CBFace --------- - IBFace2 | -----------> CBFinalFace When I compile (with all the pure abstract functions implemented), I receive the C4259 warning that "pure virtual function was not defined". The functions it lists are all the functions from IBFace. How do I get past this? It seems that even though CBFace implements all the functions, the fact that I derive from CBFace and then again from IBFace2 (which also derives from IBFace), I get the problem. any ideas?
Hello, Is your declaration like this? ========================================= class CBFace: public IBFace{...} class IBFace2: public IBFace{...} class CBFinalFace: public CBFace, public IBFace2{...} ========================================= in case it is, try using virtual inheritance. ========================================= class CBFace: virtual IBFace{...} class IBFace2: virtual IBFace{...} class CBFinalFace: virtual CBFace, virtual IBFace2{...} ========================================= I hope it helps.