There a couple of simple solutions to your current problem and like the others said you don't need an iterator here. Because you are returning a reference and you have declared
getStatus
as
const
, it automatically returns the
Status&
as a
const
and it is complaining that it cannot convert from
const Status&
to
Status&
. You can either change the return value to be a
const Status&
or const cast away the constness (In your case I would not do).
In other words, when you call a const member function, whether the object is const or not, it treats it as if this is const, you can verify this by calling a const member function from a non cost object and looking at the 'type' of the 'this' pointer, it will be a const * to a const 'whatever my object type is'
As a side note: Do you really want to return a static reference here in the first place? By returning a reference you are now exposing your private data that is Status. If what you really want is just to get the "status' status" then might I suggest this alternative, still adhering to the encapsulation of MyClass.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class myClass
{
//... Stuff in myClass
bool getStatus() const
{
return stat.getStatus();
}
//...
}
// Now main would look like this...
main()
{
myClass var;
var.getStatus();
}
|