This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Can't pass temporary with hidden copy ctor as const ref
- From: Matt Hoosier <matt dot hoosier at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Thu, 9 Apr 2009 15:22:48 -0500
- Subject: Can't pass temporary with hidden copy ctor as const ref
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