From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Artem Khodush" To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org Subject: Re: c++/3171: Copy constructor does not accept parameter by value Date: Wed, 13 Jun 2001 09:36:00 -0000 Message-id: <20010613163603.16533.qmail@sourceware.cygnus.com> X-SW-Source: 2001-06/msg00567.html List-Id: The following reply was made to PR c++/3171; it has been noted by GNATS. From: "Artem Khodush" To: Cc: Subject: Re: c++/3171: Copy constructor does not accept parameter by value Date: Wed, 13 Jun 2001 20:18:45 +0400 Arun Saini , Gurgaon wrote: > I am reproducing a portion of code and the error reported by the compiler > when I try to compile it. > > > Test someFunc(void) > { > Test tempTest; > tempTest.testVar = 10; > > return tempTest; > } > > > int main() > { > Test t1; > t1 = someFunc(); > return 0; > } > This is not a bug. Here what's going on: the compiler created a temporary variable to store the result of someFunc(), and you are trying to pass that temporary to a copy constructor taking Test& (without a const), which is not allowed in c++. You have two options: either make Test::Test copy constructor to take const Test& parameter, or use the technique invented for std::auto_ptr to overcome this very problem (which is better discussed elsewhere).