我有這段代碼來計算形狀的面積。我不明白爲什麼我得到的錯誤「預期不合格的ID之前‘雙’」和「預期(前雙」關於「類三角::三角(雙S1,S2雙,雙S3)線44:多邊形(S1, S2,S3,0.0){}「任何幫助將是非常讚賞謝謝你在前進爲什麼這不起作用? (C++)
#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;
}
http://en.cppreference.com/w/cpp/language/class類聲明... –