Re: Inaccessible but unused copy constructor causes compile fail

Discussion in 'C++' started by Ian Collins, Nov 21, 2012.

  1. Ian Collins

    Ian Collins Guest

    On 11/22/12 10:30, Andy Champ wrote:
    > Compiling this...
    >
    > struct ncnd
    > {
    > ncnd()
    > {
    > }
    > private:
    > ncnd(const ncnd& other);
    > };
    >
    > void main()
    > {
    > ncnd x = ncnd();
    > }
    >
    >
    > Comeau complains:
    > line 12: error: "ncnd::ncnd(const ncnd&)" (declared at line 7),
    > required for copy that was eliminated, is inaccessible
    > ncnd x = ncnd();
    >
    > (it also doesn't like void main() but that's beside the point)


    Not if you want your code to be correct...

    > MSVC (2010 and 2012) also fails - but when I comment out the private it
    > compiles, links and runs just fine. Why does it need the copy
    > constructor when it's about to eliminate it?


    Adding a private copy constructor is the idiomatic technique to make a
    class non-copyable. Why else would you add one?

    --
    Ian Collins
    Ian Collins, Nov 21, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Shohet
    Replies:
    1
    Views:
    476
    William F. Robertson, Jr.
    Aug 1, 2003
  2. Replies:
    7
    Views:
    477
    Default User
    Aug 4, 2006
  3. Victor Bazarov
    Replies:
    15
    Views:
    758
    Greg Comeau
    Mar 4, 2007
  4. cinsk
    Replies:
    35
    Views:
    2,593
    James Kanze
    Oct 11, 2010
  5. Replies:
    0
    Views:
    217
Loading...

Share This Page