Topic: Explicit constructor call vs Temporaries
Author: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
Date: 1996/02/01 Raw View
About the error message in this posted code:
> class T {
> T();
> ~T();
> }
>
> class X {
> X();
> ~X();
> f(T& t);
> }
>
> int main() {
> X x;
> x.f(T()); // Compiler complained on this line
> }
The 'temporary' (it is an UNNAMED) T()-object is NOT const!
Consider:
class T {
public:
T();
~T();
void nonConstFct() {}
};
int main() {
T().nonConstFct(); // Allowed!!!
}
And so the compiler should have no problem with this code!
I compiled it without any problem!
Bye.
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]