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]

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


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