J
john
Are the following functions an abuse of good usage of 'const'? I think
func3 is an abuse, but I'm not sure if func1 or func2, in isolation,
would be considered poor usage since they do not actually modify an
instance of A themselves (although they do leave the door open). Thanks.
class B;
class A
{
B* m_b;
public:
void func1(A* &a) const
{
a = const_cast<A*>(this);
}
B* func2() const { return m_b; }
// because we could do
void func3() const
{
// now we can change m_b;
B* b = func2();
// now we can change this;
A* a;
func1(a);
}
};
func3 is an abuse, but I'm not sure if func1 or func2, in isolation,
would be considered poor usage since they do not actually modify an
instance of A themselves (although they do leave the door open). Thanks.
class B;
class A
{
B* m_b;
public:
void func1(A* &a) const
{
a = const_cast<A*>(this);
}
B* func2() const { return m_b; }
// because we could do
void func3() const
{
// now we can change m_b;
B* b = func2();
// now we can change this;
A* a;
func1(a);
}
};