Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous class inheritance

#include <iostream>
#include <cmath>
using namespace std;
class Tcirculo{
        float radio;
        float diametro;
        float area;
public:
        void carea(float r){radio= r; area=(M_PI*((r*r)));}
        float cdiam(float r) {diametro = 2*r; return diametro;}
        float getr(){return radio;}
        float getd(){return diametro;}
        float geta(){return area;}

};


class Trectangulo : public Tcirculo{
        float altura;
public:
        float calca(float h, float r){altura =h;
        float arearec = getd() * h; return arearec;}
};

class Tcilindro :  public Tcirculo ,Trectangulo{
        float xx,bb;
public:
        Tcilindro(float a, float b) {xx=a;bb=b;}
        float area_total();
};

float Tcilindro::area_total(){
        int area;
        area = ((2*((getd())))+calca(bb,xx));
        return area;
}
int main(int argc, char *argv[]) {

        return 0;
}

but the problem is :

warning: direct base 'Tcirculo' inaccessible in 'Tcilindro' due to ambiguity

In member function 'float Tcilindro::area_total()':

error: reference to 'geta' is ambiguous
error: candidates are: float Tcirculo::geta()
error:                 float Tcirculo::geta()
error: reference to 'geta' is ambiguous
error: candidates are: float Tcirculo::geta()
error:                 float Tcirculo::geta()
like image 982
Emanuel Mathias Canova Avatar asked Oct 22 '22 07:10

Emanuel Mathias Canova


1 Answers

There is no need to derive Tcilindro from Tcirculo, it is sufficient if you derive it from Trectangulo.

like image 187
Asha Avatar answered Nov 09 '22 04:11

Asha