C++程序报错non-standard syntax
迷茫
迷茫 2017-04-17 13:38:42
0
2
589

我的程序如下:

#include "iostream"
using namespace std;
class Crectangle{
public:int w, h;
       void Init(int _w,int _h) {
           w = _w;
           h = _h;
       }
       int Area() {
           return w*h;
       }
       int Perimeter() {
           return 2 * (w + h);
       }

};
int main() {
    int w=0, h=0;
    cin >> w >> h;
    Crectangle r;
    r.Init(w,h);
    cout <<r.Area<< endl <<r.Perimeter;

    return 0;
}
报错是 non-standard syntax; use '&' to create a pointer to member。怎么解决?
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
刘奇

Area() and Perimeter() are both functions, brother. To call a function, please add () after the function name

大家讲道理

I guess there is something wrong with cout <<r.Area<< endl <<r.Perimeter;, try changing it to cout <<r.Area()<< 'n' <<r.Perimeter();.

In addition, the constructor can be used for initialization.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template