This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Question about use of C++ copy constructor
- From: Ian Lance Taylor <ian at airs dot com>
- To: gcc at gcc dot gnu dot org
- Date: 13 Mar 2006 11:55:44 -0800
- Subject: Question about use of C++ copy constructor
When I compile the attached test case with mainline, I get this:
foo.cc: In function ‘void foo(const B&)’:
foo.cc:3: error: ‘B::B(const B&)’ is private
foo.cc:13: error: within this context
I don't understand why, as I don't see the copy constructor being used
anywhere. It seems to me this code should create a temporary for the
duration of the statement, and pass the temporary as a reference to
b.fn. This code compiles with icc with no errors.
What is wrong with this code?
Thanks.
Ian
class B {
private:
B(const B&);
void operator=(const B&);
public:
B();
void fn(const B &other) const;
};
void foo (const B& b)
{
b.fn(B());
}