+ Reply to Thread
Results 1 to 2 of 2

Thread: What is error C2385?

  1. #1

    What is error C2385?

    Hi All,

    Following code gives me error "C2385: 'D::GetData' is ambiguous" :

    Code:
    class A
    {
    public:	
    	int GetData()
    	{
    		return 42 ;
    	}
    } ;
    
    
    class B : public A
    {
    } ;
    
    class C : public A
    {
    } ;
    
    class D : public B, public C
    {
    } ;
    
    void Func()
    {
    	D objD ;
    	int nData = objD.GetData() ;
    }
    How to resolve it?

    Help.

  2. #2
    This is error regarding virtual base class.

    There are two copies of the member of the A class exists in the D class. Whenever you use object of D compiler has to choose between two copies of the same function!

    Hence, It raises this error.

    Use below

    Code:
    class A
    {
    public:	
    	int GetData()
    	{
    		return 42 ;
    	}
    } ;
    
    class B : virtual public A
    {
    } ;
    
    class C : virtual public A
    {
    } ;
    
    class D : public B, public C
    {
    } ;
    
    void Func()
    {
    	D objD ;
    	int nData = objD.GetData() ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts