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. A problem with Diamond problem

A problem with Diamond problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 2 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.
  • T Offline
    T Offline
    thenewbee
    wrote on last edited by
    #1

    I have a base class A which is being inherited later & in one inherited class i had OVERLOADED one of the base class function. The code snippet is given below. class A{ public: virtual void fun(){ cout<<"A"; } }; class B: virtual public A{ public : void fun(){ cout<<"k"; } }; class C: virtual public A{ public: int fun(int num){ cout<<"C"; } }; class D: public C, public B{ }; void main(){ D dObj; dObj.fun(4); } Can anyone tell me why i am getting an "ambigous" error in the fn call?

    N 1 Reply Last reply
    0
    • T thenewbee

      I have a base class A which is being inherited later & in one inherited class i had OVERLOADED one of the base class function. The code snippet is given below. class A{ public: virtual void fun(){ cout<<"A"; } }; class B: virtual public A{ public : void fun(){ cout<<"k"; } }; class C: virtual public A{ public: int fun(int num){ cout<<"C"; } }; class D: public C, public B{ }; void main(){ D dObj; dObj.fun(4); } Can anyone tell me why i am getting an "ambigous" error in the fn call?

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

      thenewbee wrote:

      dObj.fun(4);

      The error came because the compiler (me also)dosent understand which function it should actually call. function of A, or B or C. Actually which class' function do u expect to get executed?

      nave [OpenedFileFinder]

      T 1 Reply Last reply
      0
      • N Naveen

        thenewbee wrote:

        dObj.fun(4);

        The error came because the compiler (me also)dosent understand which function it should actually call. function of A, or B or C. Actually which class' function do u expect to get executed?

        nave [OpenedFileFinder]

        T Offline
        T Offline
        thenewbee
        wrote on last edited by
        #3

        :laugh: The call dObj.fun(4) shld call C::fun(int) Thats wt we had learned from the concept of Overloading. . Am i correct??

        N 1 Reply Last reply
        0
        • T thenewbee

          :laugh: The call dObj.fun(4) shld call C::fun(int) Thats wt we had learned from the concept of Overloading. . Am i correct??

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

          thenewbee wrote:

          Am i correct??

          no. First can u tell me why didnt you expect B::fun(int) to get called. Both B and C are base classes of D. Isnt it..? is it because C is your favourite :laugh: ?

          nave [OpenedFileFinder]

          T 1 Reply Last reply
          0
          • N Naveen

            thenewbee wrote:

            Am i correct??

            no. First can u tell me why didnt you expect B::fun(int) to get called. Both B and C are base classes of D. Isnt it..? is it because C is your favourite :laugh: ?

            nave [OpenedFileFinder]

            T Offline
            T Offline
            thenewbee
            wrote on last edited by
            #5

            virtual void fun(){ cout<<"A"; } }; class B: virtual public A{ public : void fun(){ cout<<"k"; } }; Its not becoz C is my Fav. . :) The base class B dont have fun(int). But C have. & how will B get the fun(int)??

            T 1 Reply Last reply
            0
            • T thenewbee

              virtual void fun(){ cout<<"A"; } }; class B: virtual public A{ public : void fun(){ cout<<"k"; } }; Its not becoz C is my Fav. . :) The base class B dont have fun(int). But C have. & how will B get the fun(int)??

              T Offline
              T Offline
              thenewbee
              wrote on last edited by
              #6

              ???:confused:

              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