Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm pretty sure YOU are supposed to create the ArrayIntStorage.h header AND implement the matching ArrayIntStorage.cpp.</p> <p>Based on the "// sort data structure using std" comment you are expected to use and create a wrapper over an appropriate stl container, something like std::vector.</p> <p>Based on the "// do not read sort" comment, you should, by default, sort the vector after each insert (unless, of course, someone calls setReadSort(false) on your wrapper).</p> <p>In addition to the interface described above, you still need to implement >> and &lt;&lt;.</p> <p>UPDATE.</p> <p>Reading you question at <a href="https://stackoverflow.com/questions/5842583/c-pass-variable-from-cpp-to-header-file">C++ pass variable from .cpp to header file</a> you seem to be quite confused by all this...</p> <p>First thing first, adding support for >> and &lt;&lt; operators:</p> <p>You do this by declaring these operators in your .h file:</p> <pre><code>friend std::ostream&amp; operator&lt;&lt;(std::ostream &amp;out, const ArrayIntStorage &amp;a); friend std::ifstream &amp; operator&gt;&gt;(std::ifstream &amp;, ArrayIntStorage &amp;); </code></pre> <p>You then define their implementation in the .cpp file:</p> <pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream &amp;out, const ArrayIntStorage &amp;a) { return out; } std::ifstream &amp; operator&gt;&gt;(std::ifstream &amp;, ArrayIntStorage &amp;) { return in; } </code></pre> <p>Obviously, you need to add some proper code there, this is just to make it compile. If it still doesn't compile, check if you have included the stream headers in your .h file:</p> <pre><code>#include &lt;fstream&gt; #include &lt;iostream&gt; </code></pre> <p>Now for some general info:</p> <p>Your array storage should be based on something like std::vector. The purpose of the >> and &lt;&lt; function you need to implement is to add and retrieve int's from that container. </p> <p>Since the ArrayIntStorage is a class, once you've established the interface you need ( the public member functions in the .h file) you should only look at the .h and .cpp to flesh out the implementation.</p> <p>Once that is done, you don't need any of the "extern" madness the answers to your other question said. Look at your main function. If creates an object of your class and the fin1 stream. It then calls the >> operator you've implemented. All of this is done with local variables.</p> <p>This is how you "use the value of this variable from main.cpp". You call a member function of your class with that variable as a parameter.</p> <p>And finally, if you have all these problems with understanding header files and link errors, are you sure you've started with the proper training exercise?</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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