I have a class with a stringstream:
class NetMessageEncoder
{
std::stringstream m_ss;
std::stringstream m_numSS;
public:
NetMessageEncoder();
void beginMessage();
…
I then have another class with an instance of this class in it that I’m trying to make a vector of:
m_games.resize(100);
This line produces:
Error 1 error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' c:\Program Files\Microsoft Visual Studio 9.0\VC\include\sstream 516
I gather that it might be because the vector needs to copy the class with I guess causes the stringstream to copy by value or something?
The stringstream is indeed the cause, compiles fine if removed.
Is there a way to fix this?
Thanks
struct TableS
{
ServerPlayer* m_players[4];
SpadesGameInfo m_info;
NetSpadesGame m_game;
bool readyToPlay() const
{
int count = 0;
for(int i = 0; i < 4; ++i)
{
if(m_players[i])
{
count++;
}
}
return count >= m_info.getNumPlayers();
}
TableS()
{
for(int i = 0; i < 4; ++i)
{
m_players[i] = NULL;
}
}
};
class ServerCore : public ServerHost, public NetEventListener
{
NetEventDecoder m_dec;
NetEventEncoder m_enc;
std::vector<ServerPlayer*> m_players;
int m_totalPlayers;
std::vector<TableS> m_games;
public:
...
You can do one of the followings:
1) Override copy constructor and assignment operator of
NetMessageEncoderand deal with stream copying yourself (using a new stream for the copy could be enough in your case, I guess)2) Avoid copying of streams by using
std::vector<TableS*> m_games;instead ofstd::vector<TableS> m_games;