Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For <a href="http://cs.binghamton.edu/~sgreene/cs240-2010f/labs/lab2.html" rel="nofollow">the assignment that you're working on</a>, you <strong>do not</strong> want to be declaring variables named str1, str2, etc. You want your <code>TenStrings</code> <a href="http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/CLASSES-INTRO.html" rel="nofollow">class</a> to have a single <a href="http://www.cplusplus.com/doc/tutorial/classes/" rel="nofollow">data member</a> (call it <code>strings</code>) which is an array of ten char pointers. This array would be initialized in your <a href="http://www.fredosaurus.com/notes-cpp/oop-condestructors/constructors.html" rel="nofollow">constructor</a>.</p> <p>You have spent so much time asking questions here, so much of which cover the same basic material. You would almost certainly be better off taking a break from StackOverflow, and using that freed-up time to study some of those tutorials that I've just linked to (or any others that you may have at your disposal.)</p> <p><strong>EDIT</strong> (responding to your comment): Here's an example. It won't solve your homework problem, but it should give you some hints. Good luck. (By the way, I haven't compiled this, but I <em>think</em> it compiles.)</p> <pre><code>class SimpleExample { public: SimpleExample(); SimpleExample&amp; operator += (const SimpleExample&amp;); friend ostream&amp; operator cout(ostream&amp;, const SimpleExample&amp;); private: int myData[5]; } SimpleExample::SimpleExample() { // Initialize a new SimpleExample instance. (Note that myData[i] is // the exact same thing as this-&gt;myData[i] or (*this).myData[i] . ) for (int i = 0; i &lt; 5; i++) { myData[i] = i; } SimpleExample&amp; operator += (const SimpleExample&amp; that) { for (int i = 0; i &lt; 5; i++) { myData[i] += that.myData[i]; } return *this; } ostream&amp; operator &lt;&lt; (ostream&amp; os, const SimpleExample&amp; simp) { for (int i = 0; i &lt; 5; i++) { os &lt;&lt; that.myData[i] &lt;&lt; " "; } return os; } </code></pre>
    singulars
    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