Frage

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,

War es hilfreich?

Lösung

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; }
...
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top