Hi,
I'm having trouble compiling the following with g++ 4.2.1:
class Uncopyable
{
public:
Uncopyable(int x) {}
private:
Uncopyable(const Uncopyable & other) {}
};
class User
{
public:
void foo(int x)
{
foo(Uncopyable(x));
}
void foo(const Uncopyable & x)
{
// do something
}
};
int main ()
{
User u;
u.foo(1);
return 0;
}
The compiler complains that it can't find a copy ctor for
'Noncopyable'; why is this? It would seem that temporaries can be
passed directly as the const ref rather than needing a copy.
Message:
test.cc: In member function 'void User::foo(int)':
test.cc:11: error: 'Uncopyable::Uncopyable(const Uncopyable&)' is private