Q
quantdev2004
Hi all,
I have been deling with this kind of code:
class Foo
{
public:
void NonConstMethod()
{}
};
class Bar
{
public:
// [...] (Class simplified)
void NonLogicallyConstMethod() const
{
m_pBar->NonConstMethod();
}
private:
Foo* const m_pBar;
};
Although this is accepted by the compiler, and therefore const-correct,
I often find myself puzzled as to whether this is actually and
logically const-correct.
It just happens that NonLogicallyConstMethod() can invoke a const
method because of the way Bar is associated to Foo i.e. If I used a
class member variable this would not be allowed. The fact that the
pointer itself is const looks like a workaround (not unlike using
<mutable>).
What am I missing?
Thanks,
Quantdev2004
I have been deling with this kind of code:
class Foo
{
public:
void NonConstMethod()
{}
};
class Bar
{
public:
// [...] (Class simplified)
void NonLogicallyConstMethod() const
{
m_pBar->NonConstMethod();
}
private:
Foo* const m_pBar;
};
Although this is accepted by the compiler, and therefore const-correct,
I often find myself puzzled as to whether this is actually and
logically const-correct.
It just happens that NonLogicallyConstMethod() can invoke a const
method because of the way Bar is associated to Foo i.e. If I used a
class member variable this would not be allowed. The fact that the
pointer itself is const looks like a workaround (not unlike using
<mutable>).
What am I missing?
Thanks,
Quantdev2004