문제

I am having some definitions problems inside my class:

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();
    }

};

I get the following error message:

"Invalid arguments 'Candidates are bool isB()'"

and

"Invalid arguments 'Candidates are bool getB()'"

What is the problem?

Thank you in advance,

도움이 되었습니까?

해결책

You have to declare your getter functions const to be able to access them through the const Test& test you have.

...
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; }
...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top