我正在制作一个类似于口袋妖怪想法的游戏类型程序。我们有一个锦标赛类,它跟踪几个团队(它自己的类),它由宠物(它自己的类)组成,不同种类的宠物是 CPet 的子类。
我们正在尝试将文件名传递给 main,从 main 将该文件名传递给 Tournament 类。在 Tournament 类中,我们使用以下命令打开文件:
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 << "File error" << endl;
20 return ;
21 }
22 //get Teamlist for tournament
23 while(!(inFile.eof())){
24 CTeam* temp = new CTeam;
25 temp->ParseTeam(inFile);
26
27 TeamList.push_back(temp);
28 }
29 }
在这里,我们将 inFile 传递给 CTeam.ParseTeam,如下所示:
30 void CTeam::ParseTeam(std::istream in){
31 string readline;
32 getline(in, readline);
33 this->TeamName = readline;
34 while(!(in.eof())&&(readline != " " || readline != "/n"))
35 {
36 getline(in, readline);
37 this->Parse(readline);
38 }
39 }
我们得到了错误:
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<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)':
/usr/include/c++/4.4/bits/ios_base.h:790: error: 'std::ios_base::ios_base(const std::ios_base&)' 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<char, std::char_traits<char> >::basic_istream(const std::basic_istream<char, std::char_traits<char> >&)':
/usr/include/c++/4.4/iosfwd:53: note: synthesized method 'std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)' first required here
CTournament.cpp: In constructor 'CTournament::CTournament(const char*)':
CTournament.cpp:25: note: synthesized method 'std::basic_istream<char, std::char_traits<char> >::basic_istream(const std::basic_istream<char, std::char_traits<char> >&)' first required here
CTournament.cpp:25: error: initializing argument 1 of 'void CTeam::ParseTeam(std::istream)'
我知道有一个类似的问题,他没有包括 fstream。我们已经将它包含在两个头文件中。
我认为这可能是没有将正确的类型传递给 PraseTeam 的问题,但是我找不到任何关于如何将文件传递给 ParseTeam 以验证我是否正确执行的非常具体的内容。
提前致谢。