Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing istream into a function
    text
    copied!<p>I am making a game-type program similar to the idea of pokemon. We have a tournament class that keeps track of several teams(its own class) which consists of pets(its own class) with different kinds of pets being subclasses of CPet. </p> <p>We are attempting to pass a file name into main, from main pass that file name into the Tournament class. In the Tournament class we open the file with:</p> <pre><code> 14 //Construct a tournament 15 CTournament::CTournament(const char *Filename){ 16 //opening file 17 ifstream inFile(Filename, ios::in); 18 if(inFile.bad()){ 19 cout &lt;&lt; "File error" &lt;&lt; endl; 20 return ; 21 } 22 //get Teamlist for tournament 23 while(!(inFile.eof())){ 24 CTeam* temp = new CTeam; 25 temp-&gt;ParseTeam(inFile); 26 27 TeamList.push_back(temp); 28 } 29 } </code></pre> <p>Here we pass inFile into CTeam.ParseTeam which looks like: </p> <pre><code> 30 void CTeam::ParseTeam(std::istream in){ 31 string readline; 32 getline(in, readline); 33 this-&gt;TeamName = readline; 34 while(!(in.eof())&amp;&amp;(readline != " " || readline != "/n")) 35 { 36 getline(in, readline); 37 this-&gt;Parse(readline); 38 } 39 } </code></pre> <p>and we are getting the error:</p> <pre><code>In file included from /usr/include/c++/4.4/ios:39, from /usr/include/c++/4.4/ostream:40, from /usr/include/c++/4.4/iostream:40, from CTournament.h:11, from CTournament.cpp:8: /usr/include/c++/4.4/bits/ios_base.h: In copy constructor 'std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;::basic_ios(const std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)': /usr/include/c++/4.4/bits/ios_base.h:790: error: 'std::ios_base::ios_base(const std::ios_base&amp;)' is private /usr/include/c++/4.4/iosfwd:47: error: within this context /usr/include/c++/4.4/iosfwd: In copy constructor 'std::basic_istream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_istream(const std::basic_istream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)': /usr/include/c++/4.4/iosfwd:53: note: synthesized method 'std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;::basic_ios(const std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)' first required here CTournament.cpp: In constructor 'CTournament::CTournament(const char*)': CTournament.cpp:25: note: synthesized method 'std::basic_istream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_istream(const std::basic_istream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;)' first required here CTournament.cpp:25: error: initializing argument 1 of 'void CTeam::ParseTeam(std::istream)' </code></pre> <p>I know there is a similar question about this where he did not include fstream. We have included it in both header files.</p> <p>I thought maybe it was a problem of not passing the correct type into PraseTeam, but I could not find anything very specific on how else to pass the file into ParseTeam to verify whether I was doing it correctly or not.</p> <p>Thanks in advance.</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