public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: "Arun Saini, Gurgaon" <arun@ggn.hcltech.com>
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	[thread overview]
Message-ID: <5F0021EEA434D511BE7300D0B7B6AB533E772F@MAIL2> (raw)

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


             reply	other threads:[~2001-06-13  8:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-13  8:16 Arun Saini, Gurgaon [this message]
2001-06-13  9:36 Artem Khodush
2001-06-13 13:56 Ross Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5F0021EEA434D511BE7300D0B7B6AB533E772F@MAIL2 \
    --to=arun@ggn.hcltech.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).