5
#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;
}

但问题是:

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

在成员函数中'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()
4

2 回答 2

2

不需要从 派生,TcilindroTcirculo派生就足够了Trectangulo

于 2012-10-09T06:03:20.490 回答
1

这些问题是因为具有相同基类的多重继承。在您的示例中,类Tcilindro继承自Trectangulo并且Tcirculo已经Trectangulo派生自Tcirculo并且Tcilindro具有相同函数的双重定义。您只需要在Tcirculo此处省略类即可消除继承函数的歧义。

于 2012-10-09T06:03:25.090 回答