From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17400 invoked by alias); 18 Jun 2004 11:01:26 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 17367 invoked from network); 18 Jun 2004 11:01:23 -0000 Received: from unknown (HELO fencepost.gnu.org) (199.232.76.164) by sourceware.org with SMTP; 18 Jun 2004 11:01:23 -0000 Received: from monty-python.gnu.org ([199.232.76.173]) by fencepost.gnu.org with esmtp (Exim 4.34) id 1BbH7a-0002AN-SW for gcc-help@gnu.org; Fri, 18 Jun 2004 07:01:22 -0400 Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.34) id 1BbH7E-0000rI-Tj for gcc-help@gnu.org; Fri, 18 Jun 2004 07:01:03 -0400 Received: from [217.12.12.141] (helo=smtp804.mail.ukl.yahoo.com) by monty-python.gnu.org with smtp (Exim 4.34) id 1BbH7D-0000jg-Fo for gcc-help@gnu.org; Fri, 18 Jun 2004 07:01:00 -0400 Received: from unknown (HELO there) (gcc@gnu.org@81.131.121.170 with poptime) by smtp804.mail.ukl.yahoo.com with SMTP; 18 Jun 2004 11:00:56 -0000 Content-Type: text/plain; charset="iso-8859-1" From: Phil Prentice To: gcc-help@gnu.org, gcc@gnu.org Subject: Copy Constructor Problem with 3.2.2?? Date: Fri, 18 Jun 2004 11:01:00 -0000 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, hits=0.5 required=5.0 tests=RCVD_IN_ORBS version=2.55 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) Message-Id: X-SW-Source: 2004-06/txt/msg00181.txt.bz2 I have a problem with the copy constructor. I have knocked up a simple program that demonstrates this problem. I have compiled this same program using Visual C++ (windows) and it compiles & runs as I would have expected. When I tryed compiling this same program on 3.2.2 (& 2.96) the compiler gives the following error:- x.cc: In function `int main()': x.cc:34: no matching function for call to `Point::Point(Point)' x.cc:19: candidates are: Point::Point(Point&) There may now be good reason for this error (its been a while since I have done a lot of C++), but I'm curious as to what it is. Of course I could change ret to return a reference, but then thats not a good thing to do (return automatic variables by reference). I could make the variable that is being returned static, but again I'm not sure if thats a good thing to do? Note:- the real code that demonstrates this problem is much more complex then this example; The code I'm porting used to compile & run on a very old version of g++ and I'm trying to build it on a newer version (on Linux.). Of course I cant try and create a copy constructor Point::Point(Point) because the compiler wont let me. Any comments would be welcome CODE ===== #include class Point { protected: double x1; double y1; public: Point(); // Default constructor Point (Point& pt); // Copy Constructor Point ret(); // Member Function }; Point::Point() // Default constructor { x1=0.0; y1=0.0; } Point::Point (Point& pt) // Copy Constructor { x1 = pt.x1; y1 = pt.y1; } Point Point::ret() // General Member function { Point local; // Local variable return local; // Return it by value } main() { Point m; // Default constructor Point n=m; // COPY constructor....works Point o=m.ret(); // COPY constructor, does not compile!!! /* g++ x.cc x.cc: In function `int main()': x.cc:34: no matching function for call to `Point::Point(Point)' x.cc:19: candidates are: Point::Point(Point&) */ } Thanks for your help Phil