Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I find where a C++ copy constructor is being USED via a compile error?
    primarykey
    data
    text
    <p>In short: is there some way I can modify a class definition such that it fails to compile at <strong>the point of use</strong> of a copy constructor no matter where it's used?</p> <p>I have a very large project and was cleaning up some class definitions. There's a class that I explicitly don't want to use copy constructors on (let's ignore why that is for the sake of this discussion), and in the interest of safety, I figured I'd just define the copy constructor as private and not actually implement it... that way it would throw a compile error if I tried to use it anywhere. Lo and behold, it compiles fine, but I have a linker error... the copy constructor implementation is not found! Presumably that means it's in use somewhere, but I'm unable to find where it's being used. This is Visual Studio 2010 by the way. So my question is, is there some way I can modify the class definition such that it fails to compile at the point of use?</p> <pre><code>class Sample { private: // not implemented Sample( const Sample&amp; rhs ); Sample&amp; operator=( const Sample&amp; rhs ); public: // implemented Sample(); ... }; Sample *samp1 = new Sample; Sample *samp2 = new Sample( *samp1 ); // &lt;&lt;-- inaccessible here! this works </code></pre> <p>Presumably since I'm not hitting a compile error, but am hitting the linker error, that it means the class itself (or a friend) is doing the copy-constructed create (since that's all that would have access to the private constructor), but I sure can't find it!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload