gpt4 book ai didi

c++ - 为什么这不起作用? (C++)

转载 作者:行者123 更新时间:2023-11-28 05:08:53 25 4
gpt4 key购买 nike

我有这个代码来计算形状的面积。我不明白为什么我在第 44 行的“class Triangle::Triangle(double s1, double s2, double s3) : Polygon(s1, s2, s3, 0.0) {}。”任何帮助将不胜感激。提前致谢。

    #include "Polygon.h"
#include <iostream>
#include <cmath>
using namespace std;

//Polygon constructor
Polygon :: Polygon(double side1, double side2, double side3, double side4)
{
s1 = side1;
s2 = side2;
s3 = side3;
s4 = side4;
}
//get area method
double Polygon :: getArea()
{
float length, width, area;

if (s1 == s2)
{
length = s1;
width = s3;
}
else if (s1 == s3)
{
length = s1;
width = s2;
}
else if (s1 == s4)
{
length = s1;
width = s3;
}
area = length * width;
return area;
}
//Triangle class
class Triangle :: Triangle(double s1, double s2, double s3) : Polygon(s1, s2, s3, 0.0) {}

double Triangle :: getArea()
{
float s, area;

s = (s1 + s2 + s3)/2;
area = sqrt(s * (s - s1) * (s - s2) * (s - s3));

return area;
}

最佳答案

你需要在这里删除单词class:

class Triangle :: Triangle

当然,您需要确保在此之前声明了 class Triangle

关于c++ - 为什么这不起作用? (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43960120/

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