T
tech
Hi, I want to return a reference to member object
provided in class Test, so have
provided a getter function GetObj() and declared it
const. However i'm getting a
compiler error that i need to return reference to const
obj but if i do do this
i can't call non const member functions eg
GetObj().NonConstFoo()
How do i get round this problem. I woul think that
GetObj is logically const as
it does not change the object.This is on MSVC++ V8.0
class Obj
{
};
class Test
{
public:
Obj& GetObj() const
{
return m_obj;
}
private:
Obj m_obj;
};
provided in class Test, so have
provided a getter function GetObj() and declared it
const. However i'm getting a
compiler error that i need to return reference to const
obj but if i do do this
i can't call non const member functions eg
GetObj().NonConstFoo()
How do i get round this problem. I woul think that
GetObj is logically const as
it does not change the object.This is on MSVC++ V8.0
class Obj
{
};
class Test
{
public:
Obj& GetObj() const
{
return m_obj;
}
private:
Obj m_obj;
};