c++ - ifstream attempting reference to a deleted function -
i'm writing code virtual tournament. problem team class has ifstream object, understand stream objects not have copy constructors, therefore converted playing8 vector of team objects pointer object, team objects not copied.but error error 16 error c2280: 'std::basic_ifstream>::basic_ifstream(const std::basic_ifstream> &)' : attempting reference deleted function c:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 592 1 assignment3
how resolve without removing ifstream object team class? heres code 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(); };
code tournament constructor
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(); (int = 0; < noteam;i++){ string x=to_string(i)+".csv"; team temp(x); temp.set_teamform((6 + rand() % 5) / 10.0); teams.push_back(temp); } }
code select playing 8;
void tournament::selectplaying8(){ (int = 0; < 7; i++){ playing8.push_back(&teams[i]); playing8[i]->set_playing(); }
attributes of team class
#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; };
im using visual studio express 2013
this code
playing8.push_back(&teams[i]);
makes copy of team
class instance pushed using compiler generated copy constructor. tries copy each member.
ifstream
doesn't provide copy constructor (it's deleted), hence error.
to fix you'll need use ifstream*
pointer, or ifstream&
reference.
Comments
Post a Comment