M
MagnumOpus
Hello all,
I have a question on temporary objects.
Are the temporary objects always constant ?
class X {
int i;
public:
X (int ii = 0);
void modify();
};
X::X(int ii) { i = ii; }
void X::modify() { i = i++; }
X f5() { return X(); }
void f7(X& x) { //return by const reference
x.modify();
}
void main()
{
f7(f5());
}
As per Bruce Eckel, temporary objects are always constant.
But when i tried to compile this prograrm in VS, it doesn't complain
me at all.
Can anybody explain about this ?
Thank you
Sunil
I have a question on temporary objects.
Are the temporary objects always constant ?
class X {
int i;
public:
X (int ii = 0);
void modify();
};
X::X(int ii) { i = ii; }
void X::modify() { i = i++; }
X f5() { return X(); }
void f7(X& x) { //return by const reference
x.modify();
}
void main()
{
f7(f5());
}
As per Bruce Eckel, temporary objects are always constant.
But when i tried to compile this prograrm in VS, it doesn't complain
me at all.
Can anybody explain about this ?
Thank you
Sunil