I am passing an unnamed temporary object to a function defined with const ref parameter. The copy ctor of the class is private, and I get a compilation error. I don't understand why a copy constructor is called in this situation.
class A {
public:
A(int i) {}
private:
A(const A&) {}
};
void f(const A& a)
{
}
int main()
{
f(A(1)); // <-- error here: 'A::A(const A&)' is private
}
As expected, when I change the main to:
A a(1);
f(a);
it works.
EDIT: the compiler is gcc 4.1.2