This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/3171: Copy constructor does not accept parameter by value
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/3171: Copy constructor does not accept parameter by value
- From: "Arun Saini , Gurgaon" <arun at ggn dot hcltech dot com>
- Date: Wed, 13 Jun 2001 20:40:56 +0530
>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: