gpt4 book ai didi

c++ - 不明确的类继承

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:40:47 25 4
gpt4 key购买 nike

#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()

最佳答案

不需要从Tcirculo派生Tcilindro,从Trectangulo派生就足够了。

关于c++ - 不明确的类继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12793651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com