Topic: Is this well defined?
Author: davew@cs.umd.edu (David G. Wonnacott)
Date: 13 Nov 1994 00:17:29 GMT Raw View
Does the C++ language definition (such as it is) define the result of:
class C
{
C(const C &init) { datum = init.datum; }
C() { datum = 0; }
int datum;
};
int same_address(C &c1, C &c2)
{
return &c1 == &c2;
}
main()
{
C c;
cout << same_address(c, C(c));
}
Is the compiler required to create a distinct copy of c as the second
argument to the function call? Or could it just give me "c" again?
G++ 2.5.8 and "CC" print 0 for this, but G++ 2.6.1 prints 1.
Thanks for any enlightenment on this,
Dave Wonnacott
davew@cs.umd.edu