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. ambiguity in multiple inheritance

ambiguity in multiple inheritance

Scheduled Pinned Locked Moved C / C++ / MFC
helpoopquestion
3 Posts 3 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.
  • U Offline
    U Offline
    User 13127871
    wrote on last edited by
    #1

    i have same function in both parent classes in multiple inheritance like show(); when i m am call function show(); compiler generate an error what is the solution of this problem

    L J 2 Replies Last reply
    0
    • U User 13127871

      i have same function in both parent classes in multiple inheritance like show(); when i m am call function show(); compiler generate an error what is the solution of this problem

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

      Member 13159920 wrote:

      what is the solution of this problem

      The solution is to correct your code. We cannot guess what you have written.

      1 Reply Last reply
      0
      • U User 13127871

        i have same function in both parent classes in multiple inheritance like show(); when i m am call function show(); compiler generate an error what is the solution of this problem

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        You have to specify which show() function has to be called:

        /* derived is an instance of your class */
        derived.ParentClass1::show();
        derived.ParentClass2::show();

        You may also put this code into a new member function using a different name like showBoth() or add functions for each:

        class derived : public ParentClass1, ParentClass2
        {
        // ...
        void show1() { ParentClass1::show(); }
        void show2() { ParentClass2::show(); }
        void showBoth() { ParentClass1::show(); ParentClass2::show(); }
        };

        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