Note that there are some explanatory texts on larger screens.

plurals
  1. POCompilation warning for Objects that contain non Copyable objects are unreadable
    primarykey
    data
    text
    <p>I've asked a similiar question before but now I'd like to be more specific. The problem I face is that I have an object that contains a non copyable object and when someone wants to use my interface and he does not use it well (does try to use the object's copy constructor) he will get a compilation error that will point to the object and not his actual code. So two questions: 1. can I fix it somehow to point it to his original code line? 2. if I cannot, how can I put a static_assert that will only happen if someone actually tries to use the copy c'tor(I've tried a few but then I get them even if someone doesn't use it...)</p> <p>I am adding a sample code and the compilation error in case I was not understood... Notice the last compile error points to the ObjectHolder h. file.. while I want it to point to the main Thanks!</p> <p><em>*</em> was a mistake when I replaced names.. it is in fact the code that created the compilation error. and Let's assume I don't want to implement a private copy c'tor just to forward the disability to copy</p> <pre><code>class NonCopyableObject { public: virtual ~NonCopyableObject () {} NonCopyableObject(int i) { m_index = i;} int m_index; private: NonCopyableObject(const NonCopyableObject&amp; other) {} }; class ObjectHolder { public: virtual ~ObjectHolder (); ObjectHolder(int i) : obj(i) {} NonCopyableObject obj; }; void main() { ObjectHolder first(1); ObjectHolder second(first); } 1&gt;------ Build started: Project: tester, Configuration: Debug Win32 ------ 1&gt; main.cpp 1&gt;d:\users\someone\documents\visual studio 2012\projects\tester\tester\objectholder.h(13): error C2248: 'NonCopyableObject::NonCopyableObject' : cannot access private member declared in class 'NonCopyableObject' 1&gt; d:\users\someone\documents\visual studio 2012\projects\tester\tester\noncopyableobject.h(15) : see declaration of 'NonCopyableObject::NonCopyableObject' 1&gt; d:\users\someone\documents\visual studio 2012\projects\tester\tester\noncopyableobject.h(8) : see declaration of 'NonCopyableObject' 1&gt; This diagnostic occurred in the compiler generated function 'ObjectHolder::ObjectHolder(const ObjectHolder &amp;)' </code></pre>
    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.
    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