Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

virtuality giving problem

Posted on 1999-06-30
8
Medium Priority
?
189 Views
Last Modified: 2013-11-18
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();      
      }
0
Comment
Question by:deepakstyagi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1198797
try:
  class derv1:public derv, virtual base
0
 

Author Comment

by:deepakstyagi
ID: 1198798
no comments
0
 

Author Comment

by:deepakstyagi
ID: 1198799
i have tried
   base{}
   derv:virtual base
   derv:derv,base
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1198800
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

0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1198801
Looks like what I said, don't know waht standard has to say though.
0
 

Author Comment

by:deepakstyagi
ID: 1198802
i didn't find that answer related to the context i am speaking to..
0
 
LVL 7

Accepted Solution

by:
KangaRoo earned 400 total points
ID: 1198803
Try:

#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, virtual base
{
//public:
};

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

Like Alex and I said before. Don't tell us it's not relevant.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1198804
>> 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!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question