From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Arun Saini, Gurgaon" To: gcc-gnats@gcc.gnu.org Subject: c++/3171: Copy constructor does not accept parameter by value Date: Wed, 13 Jun 2001 08:16:00 -0000 Message-id: <5F0021EEA434D511BE7300D0B7B6AB533E772F@MAIL2> X-SW-Source: 2001-06/msg00563.html List-Id: >Number: 3171 >Category: c++ >Synopsis: Copy constructor does not accept parameter by value >Confidential: no >Severity: critical >Priority: high >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Wed Jun 13 08:16:00 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Arun Saini >Release: 3.0 20010528 (prerelease) >Organization: HCL Technologies, Gurgaon, INDIA >Environment: System: Linux ntc 2.2.16-22 #1 Tue Aug 22 16:49:06 EDT 2000 i686 unknown Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: /usr/local/src/gcc-20010528/configure --enable-threads=posix --enable-shared >Description: I am reproducing a portion of code and the error reported by the compiler when I try to compile it. class Test { public : int testVar; Test() { testVar = 0; } Test(Test& t) { testVar = t.testVar; t.testVar = 0; } Test(Test *pt) { testVar = pt->testVar; pt -> testVar = 0; } Test& operator=(Test& t) { testVar = t.testVar; t.testVar = 0; } Test& operator=(Test* pt) { testVar = pt->testVar; pt->testVar = 0; } }; Test someFunc(void) { Test tempTest; tempTest.testVar = 10; return tempTest; } int main() { Test t1; t1 = someFunc(); return 0; } When I compile this the error given is g++ test.cpp test.cpp: In function `int main()': test.cpp:49: no match for `Test& = Test' operator test.cpp:24: candidates are: Test& Test::operator=(Test&) test.cpp:30: Test& Test::operator=(Test*) >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: