Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Inaccessible but unused copy constructor causes compile fail

Reply
Thread Tools

Re: Inaccessible but unused copy constructor causes compile fail

 
 
Ian Collins
Guest
Posts: n/a
 
      11-21-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Inaccessible but unused copy constructor causes compile fail goran.pusic@gmail.com C++ 0 11-23-2012 03:05 PM
template copy constructor vs normal copy constructor cinsk C++ 35 10-10-2010 11:14 PM
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
Copy construction with inaccessible base class copy c-tor Victor Bazarov C++ 15 03-04-2007 03:47 PM
inaccessible constructor cpp_novice@yahoo.com C++ 7 08-04-2006 05:11 PM



Advertisments