Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Multipal inharitance error: conflicting

Reply
Thread Tools

Multipal inharitance error: conflicting

 
 
sumit15nov@gmail.com
Guest
Posts: n/a
 
      09-14-2012
Hi,
I am getting error on doing multipal inheritance.
Please check the below code-

class Hal
{
public:
virtual int SetPrintLoss()
{
cout << "Hal::SetPrintLoss" << endl;
}
};
class FluxGrid : public Hal
{
public:
void SomeFunction()
{
cout << "FluxGrid::SomeFunction" << endl;
}
};
class HalAmplifier
{
public:
virtual void SetPrintLoss()
{
cout << "HalAmplifier::SetPrintLoss" << endl;
}
};
class Simulator : public FluxGrid, public HalAmplifier
{
public:
virtual void SetPrintLoss()
{
cout << "Simulator::SetPrintLoss" << endl;
}
};

I am getting error : -
error: conflicting return type specified for ‘virtual void Simulator::SetPrintLoss()’
error: overriding ‘virtual int Hal::SetPrintLoss()’


please suggest me what to do now.
 
Reply With Quote
 
 
 
 
Öö Tiib
Guest
Posts: n/a
 
      09-14-2012
On Friday, September 14, 2012 11:01:08 AM UTC+3, (E-Mail Removed) wrote:
> Hi,
>
> I am getting error on doing multipal inheritance.
> Please check the below code-
>
> class Hal
> {
> public:
> virtual int SetPrintLoss()

Type 'void' here ^^^ instead of 'int'.

>
> please suggest me what to do now.


Enable warnings and pay attention to those. Most compilers warn that
Hal::SetPrintLoss() does not return anything despite being declared
int.
 
Reply With Quote
 
 
 
 
sumit15nov@gmail.com
Guest
Posts: n/a
 
      09-14-2012
On Friday, September 14, 2012 5:00:14 PM UTC+5:30, Öö Tiib wrote:
> On Friday, September 14, 2012 11:01:08 AM UTC+3, (E-Mail Removed) wrote:
>
> > Hi,

>
> >

>
> > I am getting error on doing multipal inheritance.

>
> > Please check the below code-

>
> >

>
> > class Hal

>
> > {

>
> > public:

>
> > virtual int SetPrintLoss()

>
> Type 'void' here ^^^ instead of 'int'.
>
>
>
> >

>
> > please suggest me what to do now.

>
>
>
> Enable warnings and pay attention to those. Most compilers warn that
>
> Hal::SetPrintLoss() does not return anything despite being declared
>
> int.



Thanks.
Agreed, Now Hal::SetPrintLoss() is returning 0.

the change code is -

class Hal
5 {
6 public:
7 virtual int SetPrintLoss()
8 {
9 cout << "Hal::SetPrintLoss" << endl;
10 return 0;
11 }
12 };
13 class FluxGrid : public Hal
14 {
15 public:
16 void SomeFunction()
17 {
18 cout << "FluxGrid::SomeFunction" << endl;
19 }
20 };
21 class HalAmplifier
22 {
23 public:
24 virtual void SetPrintLoss()
25 {
26 cout << "HalAmplifier::SetPrintLoss" << endl;
27 }
28 };
29 class Simulator : public FluxGrid, public HalAmplifier
30 {
31 public:
32 virtual void SetPrintLoss()
33 {
34 cout << "Simulator::SetPrintLoss" << endl;
35 }
36 };

-----------------------------------------
sumit15nov@in-lnxbld99:~/code$ g++ -Wall -Wextra -pedantic -c multipal-inharitance-error.cpp
multipal-inharitance-error.cpp:42: error: conflicting return type specifiedfor ‘virtual void Simulator::SetPrintLoss()’
multipal-inharitance-error.cpp:7: error: overriding ‘virtual int Hal::SetPrintLoss()’
sumit15nov@in-lnxbld99:~/code$
--------------------------------------------

It is very clear what is happening, please need some suggestion .






 
Reply With Quote
 
Öö Tiib
Guest
Posts: n/a
 
      09-14-2012
On Friday, September 14, 2012 3:25:45 PM UTC+3, (E-Mail Removed) wrote:
> On Friday, September 14, 2012 5:00:14 PM UTC+5:30, Öö Tiib wrote:
> > On Friday, September 14, 2012 11:01:08 AM UTC+3, (E-Mail Removed) wrote:
> > > Hi,
> > >
> > > I am getting error on doing multipal inheritance.
> > > Please check the below code-
> > >
> > > class Hal
> > > {
> > > public:
> > > virtual int SetPrintLoss()

> > Type 'void' here ^^^ instead of 'int'.
> >
> > >
> > > please suggest me what to do now.

> >
> > Enable warnings and pay attention to those. Most compilers warn that
> > Hal::SetPrintLoss() does not return anything despite being declared
> > int.

>
> Thanks.
> Agreed, Now Hal::SetPrintLoss() is returning 0.
> the change code is -
>
> class Hal
> 5 {
> 6 public:
> 7 virtual int SetPrintLoss()
> 8 {
> 9 cout << "Hal::SetPrintLoss" << endl;
> 10 return 0;
> 11 }
> 12 };
> 13 class FluxGrid : public Hal
> 14 {
> 15 public:
> 16 void SomeFunction()
> 17 {
> 18 cout << "FluxGrid::SomeFunction" << endl;
> 19 }
> 20 };
> 21 class HalAmplifier
> 22 {
> 23 public:
> 24 virtual void SetPrintLoss()
> 25 {
> 26 cout << "HalAmplifier::SetPrintLoss" << endl;
> 27 }
> 28 };
> 29 class Simulator : public FluxGrid, public HalAmplifier
> 30 {
> 31 public:
> 32 virtual void SetPrintLoss()
> 33 {
> 34 cout << "Simulator::SetPrintLoss" << endl;
> 35 }
> 36 };
>
> -----------------------------------------
> sumit15nov@in-lnxbld99:~/code$ g++ -Wall -Wextra -pedantic -c multipal-inharitance-error.cpp
> multipal-inharitance-error.cpp:42: error: conflicting return type specified for ‘virtual void Simulator::SetPrintLoss()’
> multipal-inharitance-error.cpp:7: error: overriding ‘virtual int Hal::SetPrintLoss()’
> sumit15nov@in-lnxbld99:~/code$
> --------------------------------------------
>
> It is very clear what is happening, please need some suggestion .


Problem is that you have overrides with same signature but non-compatible return type. There a re lot of solutions.
1) You can have different functions (for example rename 'Hal::SetPrintLoss()' as 'Hal::SetLoss()' )
2) You can make them valid overrides of same inheritance tree. Should havesame return type then.
3) You can make the signatures different and so turn them into overloads (for example have 'int Hal::SetPrintLoss(int)' instead of 'int Hal::SetPrintLoss()').
4) You can stop using language features that you do not understand in yourcode.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conflicting Indicators about Network to which I'm connected =?Utf-8?B?c3Rhcmxpbmc=?= Wireless Networking 1 01-30-2006 12:16 PM
multiple inharitance super() question Alex Greif Python 1 11-14-2005 12:48 PM
Conflicting uses of "ip dhcp-server" -- design flaw? kenw@kmsi.net Cisco 7 08-15-2005 05:14 PM
address violation on cisco switch - conflicting documentation?? NNTP Cisco 1 09-14-2004 08:00 PM
Re: address violation on cisco switch - conflicting documentation?? Kevin Widner Cisco 0 09-14-2004 05:51 PM



Advertisments