The following code only works when the copy constructor is available.
When I add print statements (via std::cout) and make the copy constructor availa
From http://gcc.gnu.org/gcc-3.4/changes.html
When binding an rvalue of class type to a reference, the copy constructor of the class must be accessible. For instance, consider the following code:
class A
{
public:
A();
private:
A(const A&); // private copy ctor
};
A makeA(void);
void foo(const A&);
void bar(void)
{
foo(A()); // error, copy ctor is not accessible
foo(makeA()); // error, copy ctor is not accessible
A a1;
foo(a1); // OK, a1 is a lvalue
}
This might be surprising at first sight, especially since most popular compilers do not correctly implement this rule (further details).
This will be fixed in C++1x by Core Issue 391.