Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is better to use the containers provided by STL rather than describing your own (unless you have proven it to be unsuitable). If the (sub)containers are ordered, but not sorted by their ID, then a <code>vector</code> or <code>deque</code> would probably be good choices. All STL containers have a <code>size()</code> method that reports the number of elements held by the container.</p> <p>You also did not make any of your members public in your model. You will either need to make them public, or provide public accessors, or define friends. As a model, you should probably define public interfaces, so that you will be free to modify your implementation later while leaving your model intact.</p> <p>In your model, <code>Document</code> looks exactly like a <code>Container</code> except for the ID, so it could be factored out.</p> <pre><code>class Container; typedef std::vector&lt;Container&gt; Containers; class ContainerOwner { protected: std::string m_name; Containers m_list; }; class Document : public ContainerOwner { public: std::string &amp; DocumentName () { return m_name; } const std::string &amp; DocumentName () const { return m_name; } Containers &amp; ContainerList () { return m_list; } const Containers &amp; ContainerList () const { return m_list; } }; class Container : public ContainerOwner { int m_id; public: std::string &amp; ContainerName () { return m_name; } const std::string &amp; ContainerName () const { return m_name; } int &amp; ContainerId () { return m_id; } int ContainerId () const { return m_id; } Containers &amp; SubContainerList () { return m_list; } const Containers &amp; SubContainerList () const { return m_list; } }; </code></pre>
 

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