삼각형의 삼각형의 높이와 높이를 읽고 그 영역을보고하는 프로그램을 만들고 있습니다. 그것은 나를 준다삼각형의 면적을 계산하는 중 오류가 발생 했습니까?
#include<iostream>
using namespace std;
// a simple triangle class with a base and a height
class Triangle {
public:
double setbase(double x) { //was void but changed it to double
base = x;
}
double setheight(double y) {
height = y;
}
double getbase() {
return base;
}
double getheight() {
return height;
}
private:
double base, height;
};
double area(double, double);
int main() {
Triangle isoscoles1;
isoscoles1.setbase;
isoscoles1.setheight;
cin >> isoscoles1.setheight;
cin >> isoscoles1.setbase;
double x = isoscoles1.getbase;
double y = isoscoles1.getheight;
cout << "Triangle Area=" << area(x,y) << endl;
system("pause>nul");
}
double area(double x, double y) {
double a;
a = (x*y)/2;
return a;
}
이 오류는 다음과 같습니다 : 여기에 지금까지 가지고 무엇 -
Severity Code Description Project File Line Suppression State
Error C3867 'Triangle::setbase': non-standard syntax; use '&' to create a pointer to member Project1 c:\users\ku\desktop\test\project1\main.cpp 50
Error C3867 'Triangle::setheight': non-standard syntax; use '&' to create a pointer to member Project1 c:\users\ku\desktop\test\project1\main.cpp 51
Error C2679 binary '>>': no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) Project1 c:\users\ku\desktop\test\project1\main.cpp 54
Error C2679 binary '>>': no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion) Project1 c:\users\ku\desktop\test\project1\main.cpp 55
Error C3867 'Triangle::getbase': non-standard syntax; use '&' to create a pointer to member Project1 c:\users\ku\desktop\test\project1\main.cpp 56
Error C3867 'Triangle::getheight': non-standard syntax; use '&' to create a pointer to member Project1 c:\users\ku\desktop\test\project1\main.cpp 57
내가 잘못 여기서 뭐하는 거지?
은 [좋은 책] 학습 고려 (https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), 무작위로 코드를 작성하는 것보다. –
별로 유용하지 않습니다. 하지만 방문해 주셔서 감사합니다 – LogomonicLearning
왜 유용하지 않습니까?당신이 만든 실수는 그와 관련된 문법이 좋은 책의 첫 번째 장에서 다루어 져야한다는 것은 매우 사소한 것입니다. 독서를 제안함으로써 나는 미래에 더 많은 유사한 문제를 만들지 못하게 할 수 있습니다. –