"Zheka" <zh***@netvision.net.il> wrote in message
news:4d**************************@posting.google.c om...
we're dealing the following problem:
d:\Program Files\Microsoft Visual Studio .NET\Vc7\include\vector(575):
error C2440: 'initializing' : cannot convert from 'const Game' to
'Game'
This error comes because of the following:
Game newGame(numPlayers, playerNames, boardKind);
games.insert(games.end(), newGame);
games is a vector <Game>
and Game is:
class Game
{
public:
Game(const int numPlayers, const vector <string> playerNames, bool
boardKind);
void playOneRound();
private:
vector <Player> players;
Board board;
Heap heap;
Dictionary dict;
};
We began getting this error only after the field Dictionary dict was
added. The class Dictionary includes ifstream dictionaryFile;
Could this cause this problem?? What could this be?
Please help :(
Not anything can be inserted into a vector. Any STL class must be Copy
Constructible and Assignable. ifstream is neither, so anything that includes
an ifstream cannot be inserted in a vector, unless you write your own copy
constructor and assignment operator for Dictionary.
Suggest you do this but consider very carefully what it means to copy an
ifstream object. How can you have two Dictionary objects using the same
file? Will you open the same file twice (not very efficient). Or maybe you
will have a pointer to the file, so two Dictionaries will have a pointer to
the same ifstream, but then how do you know when to close the file, you will
have to count the number of pointers. In short you have some thinking to do,
and some learning, find a book that discusses smart pointers, they are
probably the answer to this particular problem.
John