2013-07-15 112 views
1

我有一些定义我的班级里面的问题:成员函数的类构造函数中调用

class Test{ 

protected: 

    int a; 
    int *b; 
    Teste() {} 

public: 

    int getA() {return a;} 
    int getB() {if (b) return *b; else return 0;} 
    bool isB() {if(b) return true; else return false;} 
    Test(int a1, int b1): a(a1) {b = new int(b1);} 
    Test(const Test& test) { 
     if (test.isB()) 
     this->b = new int(test.getB()); 
     this->a = test.getA(); 
    } 

}; 

我收到以下错误信息:

“无效参数‘考生布尔ISB()’”

“无效参数 '考生布尔getB()'”

问题是什么?

谢谢你在前进,

回答

4

你必须声明你的getter函数常量才能通过你有常量测试&测试访问它们。

... 
int getA() const { return a; } 
int getB() const { if (b) return *b; else return 0; } 
bool isB() const { if(b) return true; else return false; } 
... 
相关问题