Link to home
Start Free TrialLog in
Avatar of deepakstyagi
deepakstyagi

asked on

virtuality giving problem

This code gives error message "ambiguity in base class"
somebody will tell me the cause for this error message?????


#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
class base
{
public:       
virtual void func()      
{      cout<<"base";      
}      
};

class derv: virtual public base
{
public:  
      void func1()
      {      cout<<"derived";      }            
};

class derv1:public derv,base
{
public:
};

main()
{      
      base b;      
        derv* d;
      derv1 c;      
      d=&c;            
         b.func();      
         d->func1();      
      }
Avatar of KangaRoo
KangaRoo

try:
  class derv1:public derv, virtual base
Avatar of deepakstyagi

ASKER

no comments
i have tried
   base{}
   derv:virtual base
   derv:derv,base
I translate you example with BC 5.01 and get warning:
Base class 'class1' is also a base class of 'class2'
Compiler warning

(Command-line option to suppress warning: -w-ibc)

A class inherits from the same base class both directly and
indirectly.  It is best to avoid this non-portable construct
in your program code.
Choose Options|Project|Messages|Potential C++
Errors to control the display of this warning from the IDE.
Default = On
I other words, you class "derv1" inheris class "base"
directly
>> class derv1:public derv,base
and indirectly from class  "derv".
Compilator(BC) thinks, that it is not best idea, but can survive! But can be VC thinks other....
Good Luck, Alex

Looks like what I said, don't know waht standard has to say though.
i didn't find that answer related to the context i am speaking to..
ASKER CERTIFIED SOLUTION
Avatar of KangaRoo
KangaRoo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> somebody will tell me the cause for this error  message?????
I think, i was!
>> you class "derv1" inheris class "base"
>> directly and indirectly from class  "derv".
And KangaRoo tells this!