This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about use of C++ copy constructor


Hi,
	Didn't see a reply yet, so I'll chime in.

The relevant text appears in gcc-3.4's release notes:
"When binding an rvalue of class type to a reference, the copy constructor
of the class must be accessible."

PR 12226 seems to be the mother bug related to this (many dupes).

Fang

> 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?
>
> 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());
> }
>




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]