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 problem

Multiple Inheritance problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpoopquestion
8 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.
  • R Offline
    R Offline
    Rahul Vaishnav
    wrote on last edited by
    #1

    Hi all, I have one problem in using Multiple Inheritance, please go through below Code

    class Base1
    {
    public:
    void Show()
    {
    cout<<"Base1";
    }

    };
    class Base2
    {
    public:
    void Show()
    {
    cout<<"Base2";
    }
    };
    class Derived: public Base1,public Base2
    {
    }
    main()
    {
    Derived d;
    d.Show();
    }

    Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?

    S N C 3 Replies Last reply
    0
    • R Rahul Vaishnav

      Hi all, I have one problem in using Multiple Inheritance, please go through below Code

      class Base1
      {
      public:
      void Show()
      {
      cout<<"Base1";
      }

      };
      class Base2
      {
      public:
      void Show()
      {
      cout<<"Base2";
      }
      };
      class Derived: public Base1,public Base2
      {
      }
      main()
      {
      Derived d;
      d.Show();
      }

      Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?

      S Offline
      S Offline
      Symfund
      wrote on last edited by
      #2

      What's the difference between upcasting and downcasting?

      R C 2 Replies Last reply
      0
      • S Symfund

        What's the difference between upcasting and downcasting?

        R Offline
        R Offline
        Rahul Vaishnav
        wrote on last edited by
        #3

        Symfund wrote:

        What's the difference between upcasting and downcasting?

        I am sorry but,I didn't get how this question answers my question?

        1 Reply Last reply
        0
        • R Rahul Vaishnav

          Hi all, I have one problem in using Multiple Inheritance, please go through below Code

          class Base1
          {
          public:
          void Show()
          {
          cout<<"Base1";
          }

          };
          class Base2
          {
          public:
          void Show()
          {
          cout<<"Base2";
          }
          };
          class Derived: public Base1,public Base2
          {
          }
          main()
          {
          Derived d;
          d.Show();
          }

          Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          Rahul Vaishnav wrote:

          d.Show();

          The error is because the compiler do not know which Show() function it should call. Show() of Base1 or Base2. Actually which one do you want to call? You have to tell the compiler which one excatly. like d.Base1::Show(); or d.Base2::Show();

          nave [My Articles] [My Blog]

          R 1 Reply Last reply
          0
          • R Rahul Vaishnav

            Hi all, I have one problem in using Multiple Inheritance, please go through below Code

            class Base1
            {
            public:
            void Show()
            {
            cout<<"Base1";
            }

            };
            class Base2
            {
            public:
            void Show()
            {
            cout<<"Base2";
            }
            };
            class Derived: public Base1,public Base2
            {
            }
            main()
            {
            Derived d;
            d.Show();
            }

            Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            Why do you need such multiple inheritance? :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            1 Reply Last reply
            0
            • S Symfund

              What's the difference between upcasting and downcasting?

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              And what are the differences between Bose-Einstein and Dirac-Fermi statistics? :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              S 1 Reply Last reply
              0
              • N Naveen

                Rahul Vaishnav wrote:

                d.Show();

                The error is because the compiler do not know which Show() function it should call. Show() of Base1 or Base2. Actually which one do you want to call? You have to tell the compiler which one excatly. like d.Base1::Show(); or d.Base2::Show();

                nave [My Articles] [My Blog]

                R Offline
                R Offline
                Rahul Vaishnav
                wrote on last edited by
                #7

                Thank you...

                1 Reply Last reply
                0
                • C CPallini

                  And what are the differences between Bose-Einstein and Dirac-Fermi statistics? :-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  S Offline
                  S Offline
                  Symfund
                  wrote on last edited by
                  #8

                  Syntax Error: WOW! Chinglish! I am not a native English speaker. ;P

                  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