This is the mail archive of the gcc-bugs@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]

c++/3171: Copy constructor does not accept parameter by value



>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:


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