public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Copy Constructor w/gcc411
@ 2007-02-09  9:37 Phy Prabab
  2007-02-09 12:01 ` John Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: Phy Prabab @ 2007-02-09  9:37 UTC (permalink / raw)
  To: gcc-help

Hello,

I am curious, I have the test case listed which compiles fine with
gcc323 and Sun compiler 10 and 11.  The way around the gcc error is to
move the coy constructor out of private.  What am I doing wrong WRT
gcc411?  I have remarked the workaround.

[~/test]$ g++ test.c -o test
test.c: In function 'int main()':
test.c:12: error: 'A::A(const A&)' is private
test.c:21: error: within this context
[~/test]$ g++ --version
g++ (GCC) 4.1.1
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[~/test]$


TIA,
Phy

[~/test}$ cat test.c
#include <iostream>
using namespace std;

class A{
public:
  A(int i){
    a = i;
  }

  //A(const A&);
private:
  A(const A&);
  int a;
};

void f(const A&){
  printf("Hello!\n");
}

int main(){
  f(A(1));
  return 0;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Copy Constructor w/gcc411
  2007-02-09  9:37 Copy Constructor w/gcc411 Phy Prabab
@ 2007-02-09 12:01 ` John Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: John Love-Jensen @ 2007-02-09 12:01 UTC (permalink / raw)
  To: Phy Prabab, MSX to GCC

Hi Phy,

> What am I doing wrong WRT gcc411?

You are doing nothing wrong WRT gcc411.

What you are doing is wrong WRT C++.

C++ requires accessibility of the copy constructor for the temporary, even
though the copy constructor was eliminated.

You can work around that issue by making a named variable and passing in the
named variable to the function.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-09 11:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-09  9:37 Copy Constructor w/gcc411 Phy Prabab
2007-02-09 12:01 ` John Love-Jensen

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).