Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Multiple Inheritance question

Multiple Inheritance question

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structuresoophelp
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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?

    T U 2 Replies Last reply
    0
    • L Lost User

      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?

      T Offline
      T Offline
      thowra
      wrote on last edited by
      #2

      If I understand your problem correctly, I think you are expecting CBFinalFace to inherit the functionality implemented in IBFace by the CBFace class. This is not possible in COM, you can only inherit the actual interface. You will have to implement functions in CBFinalFace for your IBFace2 interface and your IBFace 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!"

      L 1 Reply Last reply
      0
      • T thowra

        If I understand your problem correctly, I think you are expecting CBFinalFace to inherit the functionality implemented in IBFace by the CBFace class. This is not possible in COM, you can only inherit the actual interface. You will have to implement functions in CBFinalFace for your IBFace2 interface and your IBFace 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!"

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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 :)

        M 1 Reply Last reply
        0
        • L Lost User

          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 :)

          M Offline
          M Offline
          Marcello
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • L Lost User

            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?

            U Offline
            U Offline
            User 2089709
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups