I
indrawati.yahya
Hi
The following code compiles fine on VC++2003, but am I violating any
standards in writing such code? More specifically, why can a const
member function call a non-const member function of a reference type
member? It seems strange and unintuitive to me. Thanks!
class T
{
public:
void B() { a = 10; }
private:
int a;
};
class A
{
public:
A(T& t_): t(t_) {}
void Test() const
{
t.B();
}
private:
T& t;
};
int main()
{
T t;
A a(t);
a.Test();
}
The following code compiles fine on VC++2003, but am I violating any
standards in writing such code? More specifically, why can a const
member function call a non-const member function of a reference type
member? It seems strange and unintuitive to me. Thanks!
class T
{
public:
void B() { a = 10; }
private:
int a;
};
class A
{
public:
A(T& t_): t(t_) {}
void Test() const
{
t.B();
}
private:
T& t;
};
int main()
{
T t;
A a(t);
a.Test();
}