Multipal inharitance error: conflicting

Discussion in 'C++' started by sumit15nov@gmail.com, Sep 14, 2012.

  1. Guest

    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.
     
    , Sep 14, 2012
    #1
    1. Advertising

  2. Öö Tiib Guest

    On Friday, September 14, 2012 11:01:08 AM UTC+3, 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.
     
    Öö Tiib, Sep 14, 2012
    #2
    1. Advertising

  3. Guest

    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, 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 .
     
    , Sep 14, 2012
    #3
  4. Öö Tiib Guest

    On Friday, September 14, 2012 3:25:45 PM UTC+3, 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, 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.
     
    Öö Tiib, Sep 14, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGF2ZQ==?=

    Conflicting dependency error/warning message

    =?Utf-8?B?RGF2ZQ==?=, Oct 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    448
    =?Utf-8?B?RGF2ZQ==?=
    Oct 26, 2004
  2. user

    error, conflicting types

    user, Jan 11, 2005, in forum: C++
    Replies:
    6
    Views:
    9,929
    rossum
    Jan 12, 2005
  3. Alex Greif

    multiple inharitance super() question

    Alex Greif, Nov 14, 2005, in forum: Python
    Replies:
    1
    Views:
    552
    Peter Otten
    Nov 14, 2005
  4. Skybuck Flying
    Replies:
    5
    Views:
    758
    ImpalerCore
    Nov 29, 2011
  5. Replies:
    1
    Views:
    143
Loading...

Share This Page