Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Re: Inaccessible but unused copy constructor causes compile fail (http://www.velocityreviews.com/forums/t954738-re-inaccessible-but-unused-copy-constructor-causes-compile-fail.html)

Ian Collins 11-21-2012 09:34 PM

Re: Inaccessible but unused copy constructor causes compile fail
 
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


All times are GMT. The time now is 09:37 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.