Pergunta

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,

Foi útil?

Solução

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; }
...
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top