Troubles with private member pointer.

Considering the class header

1
2
3
4
5
class DadosBarraRolagem
{
private:
    BarraRolagem* barraRolagem;
...

and the implmementation

1
2
3
4
5
6
7
8
DadosBarraRolagem::DadosBarraRolagem(): barraRolagem(NULL), posicao(Zoom::Oposta), modo(Qt::ScrollBarAsNeeded)
{
}

BarraRolagem*& getBarraRolagem()
{
    return *&barraRolagem;
}

compiler is returning

1
2
dadosbarrarolagem.cpp: In function 'BarraRolagem*& getBarraRolagem()':
dadosbarrarolagem.cpp:9: error: 'barraRolagem' was not declared in this scope


What it's happening?

Thanks in advanve.
It should be BarraRolagem*& DadosBarraRolagem::getBarraRolagem()
And *&barraRolagem is unnecessary, return barraRolagem; is sufficient.
Aren't you supposed to do

1
2
3
4
BarraRolagem*& DadosBarraRolagem::getBarraRolagem()
{
    return *&barraRolagem;
}
Last edited on
Thanks Athar, problem solved!

But I don't understand the difference between the two lines below, could you please tell a little bit more. I was considering that the second one is ever sufficient.

BarraRolagem*& DadosBarraRolagem::getBarraRolagem()

and

BarraRolagem*& getBarraRolagem()
Last edited on
You can have more than one getBarraRolagem() function belonging to different classes and namespaces so there is no way the compiler can know that you actually mean the one in the DadosBarraRolagem class if you don't say so explicitly.
How is the compiler (or anyone else) supposed to know it's a member function of DadosBarraRolagem if you don't say so?
You did it for the constructor too, same thing.
closed account (zb0S216C)
The first line indicates that getBarraRolagem() resides within the scope of DadosBarraRolagem. The second line indicates that getBarraRolagem() resides within the global namespace.

Wazzak
Ok guys, now I got it. Thanks to all!

In addition, I would like to say that there is only one getBarraRolagem() at all. For this reason, I was expecting compiler could discover that it belongs to DadosBarraRolagem.

Any comments are welcome.
In addition, I would like to say that there is only one getBarraRolagem() at all.

When you omit the scope resolution operator, then there will be two. You don't have to declare functions in global namespace first.
Topic archived. No new replies allowed.