Note that there are some explanatory texts on larger screens.

plurals
  1. POcopyable data class in C++
    text
    copied!<p>Inspired by <a href="http://www.codedread.com/blog/archives/2005/03/23/writing-copyable-c-classes/" rel="nofollow">this article</a>, I have a class which contains a nested copyable data class. This copyable class has no dynamic memory allocation, protect or private for its member class. </p> <pre><code>Class Domain { public: // copyable class struct CopyableDataClass { int i; } void method1(const CopyableDataClass&amp; data){...} void method2(const CopyableDataClass&amp; data){...} } </code></pre> <p>Also, by reading <a href="http://en.wikipedia.org/wiki/Object_copy" rel="nofollow">this Wikipedia page</a>, I could not use dynamic memory allocation for "CopyableDataClass" itself, to avoid the shallow copy, like </p> <pre><code>Domain::CopyableDataClass* p1=new CopyableDataClass(); Domain::CopyableDataClass* p2; p2=p1; </code></pre> <p>But what about the "Domain" Class, is it also special, e.g., can I do it as follows?</p> <pre><code>Class User { public: Domain* getter(); void setter(const Domain* data); private: Domain* m_data; //pointer ok? private ok? } </code></pre> <p>Or I have to put it into public like the copyable class,</p> <pre><code>Class User { public: Domain m_data; } </code></pre> <p>Besides the general class design rule (encapsulation, etc.), is there any constraint (protect/private/dynamic memory allocation) to the usage of this "Domain" class. I guess the constraints only apply to the "Copyable" class. Am I right? </p> <p>Thanks for any comments.</p>
 

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