Inheritance Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shyam Goyal
    New Member
    • Feb 2008
    • 1

    Inheritance Problem

    Hello Friends,

    #include "iostream.h "

    class A
    {
    public:

    void fun( int i )
    {
    cout<<"A:Fun"<e ndl
    }
    };

    class B
    {
    public:

    void fun( int i, int j )
    {
    cout<<"B:Fun"<e ndl
    }
    };

    class C: public A, public B
    {
    public:
    void Print()
    {
    cout<<"C:Print" <<endl;
    }
    };

    int main()
    {
    C obj;
    obj.fun(0);
    }

    When I am trying to compile this code I am getting the error C2385: 'C::fun is ambiguousin VC6.

    I am not able to understand why I am getting this error because the function fun is having the different number of argument in class A and class B. Even I change the type of the argument compiler is giving the same error.
  • ashitpro
    Recognized Expert Contributor
    • Aug 2007
    • 542

    #2
    Originally posted by Shyam Goyal
    Hello Friends,

    #include "iostream.h "

    class A
    {
    public:

    void fun( int i )
    {
    cout<<"A:Fun"<e ndl
    }
    };

    class B
    {
    public:

    void fun( int i, int j )
    {
    cout<<"B:Fun"<e ndl
    }
    };

    class C: public A, public B
    {
    public:
    void Print()
    {
    cout<<"C:Print" <<endl;
    }
    };

    int main()
    {
    C obj;
    obj.fun(0);
    }

    When I am trying to compile this code I am getting the error C2385: 'C::fun is ambiguousin VC6.

    I am not able to understand why I am getting this error because the function fun is having the different number of argument in class A and class B. Even I change the type of the argument compiler is giving the same error.
    Same problem has already come to this forum.
    please check below thread



    The program is indeed in error. There are two kinds of ambiguity:
    (1) name lookup ambiguity
    (2) call ambiguity.

    Since overload resolution takes place only after name lookup, you
    can't expect overload resolution to pick A::fun, when you're already in
    trouble with (1).

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Plus you are using iostream.h.

      That is the pre-ANS C++ used before 1998.

      You should be using iostream.

      Comment

      Working...