我正在为一个虚拟锦标赛编写代码。问题是团队类有一个ifstream对象,我知道流对象没有复制构造函数,因此我将playing8从团队对象的向量转换为指向对象的指针,以便不会复制团队对象。但现在我遇到了这个错误。
Error 16 error C2280:
'std::basic_ifstream<char,std::char_traits<char>>::basic_ifstream(const std::basic_ifstream<char,std::char_traits<char>> &)' :
attempting to reference a deleted function
c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 592 1 Assignment3
我该如何解决这个问题,而不需要从team类中删除ifstream对象?
以下是tournament.h的代码:#include "team.h"
class Tournament
{
std::ofstream out_file;
std::ifstream in_file;
std::vector<team> teams;
std::vector<team*> playing8;
public:
void schedule();
void schedule2();
void tfinal();
void selectPlaying8();
void rankTeams();
void match(int,int);
Tournament();
~Tournament();
};
比赛构造器的代码:
Tournament::Tournament()
{
srand(time(NULL));
in_file.open("team_list.txt");
string input;
int noteam=0;
while (getline(in_file, input)){
noteam++;
}
in_file.close();
for (int i = 0; i < noteam;i++){
string x=to_string(i)+".csv";
team temp(x);
temp.set_teamform((6 + rand() % 5) / 10.0);
teams.push_back(temp);
}
}
选择播放8的代码:
void Tournament::selectPlaying8(){
for (int i = 0; i < 7; i++) {
playing8.push_back(&teams[i]);
playing8[i]->set_playing();
}
}
团队类的属性
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include "Player.h"
class team
{
private:
std::ifstream in_file;
std::vector<Player> playing11;
std::string teamname;
std::vector<Player> player;
bool playing;
float matchperformance;
float teamform;
float team_rank_score;
};
我正在使用Visual Studio Express 2013。
ifstream
oftream
字段。实际上,我相信你根本不需要它们,可以使用引用从类外部传递它们。 - πάντα ῥεῖ