R
Ruben Campos
Is the next code legal in standard ANSI C++? (I've suppressed constructors,
destructors and extra stuff both for focusing in the real problem and for
readability).
class ClassA
{
public:
void f ( ) { /* ... */ }
};
class ClassB
{
public:
ClassA & GetARef ( ) { return mData; }
private:
ClassA mData;
};
int main (int argn, char ** argc)
{
ClassB b;
b.A().f();
}
And if ClassB::GetARef was declared as const, and ClassB::mData as mutable?
I've encountered this problem after disabling Microsoft extensions to the
languageC++ in MS Visual Studio .NET 2003, while I could compile wit those
extensions activated without any problem. I don't know if it's a compiler
matter, or if I am not fitting to the standard.
Thank you very much in advance.
destructors and extra stuff both for focusing in the real problem and for
readability).
class ClassA
{
public:
void f ( ) { /* ... */ }
};
class ClassB
{
public:
ClassA & GetARef ( ) { return mData; }
private:
ClassA mData;
};
int main (int argn, char ** argc)
{
ClassB b;
b.A().f();
}
And if ClassB::GetARef was declared as const, and ClassB::mData as mutable?
I've encountered this problem after disabling Microsoft extensions to the
languageC++ in MS Visual Studio .NET 2003, while I could compile wit those
extensions activated without any problem. I don't know if it's a compiler
matter, or if I am not fitting to the standard.
Thank you very much in advance.