Reputation:
I'm really new to C++ and I'm having a confusion over something. What I've achieved so far is:
What I want to do next is:
In Squirrel I could do:
local playerInfo = {}; // Create a table
playerInfo[ playerId ] <- CPlayer();
// To remove it -
playerInfo.rawdelete( playerId );
Not sure what would be best in C++ to reproduce this.
Upvotes: 0
Views: 83
Reputation: 1033
You can use std::map as shown below. Below sample should give fair idea on the usage.
std::map<into, PlayersInfo> mapPlayerInfo:
int nPlayerId1 = 1; // Player 1 Id sample
int nPlayerId2 = 2; // Player 2 Id sample
PlayerInfo player1(nPlayerId1,...); // Additional arguments to constructor if required
mapPlayerInfo[nPlayerId1] = player1;
PlayerInfo player2(nPlayerId2,...); // Sample 2
mapPlayerInfo[nPlayerId2] = player2;
//Deleting based on player Id
mapPlayerInfo.erase(nPlayerId1);
Upvotes: 0
Reputation: 88027
Having just looked up what a table is in Squirrel, and from reading the question above it seems the C++ version of what you want is
#include <map>
std::map<int, CPlayer> playerInfo;
The equivalent of playerInfo[ playerId ] <- CPlayer();
would be
playerInfo[playerId] = CPlayer();
and the equivalent of playerInfo.rawdelete( playerId );
would be
playerInfo.erase(playerId);
More information here
Upvotes: 4