问题描述
我的程序如下:
#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。怎么解决?
问题解答
回答1:Area()和Perimeter()都是函数啊兄弟,调用函数请在函数名后面加上()
回答2:估计是cout <<r.Area<< endl <<r.Perimeter;有问题,改成cout <<r.Area()<< ’n’ <<r.Perimeter();试试。
另外初始化可以使用构造函数。

