I'm putting objects in a map(code below) when i try to get it the object is empty!
Server s;
s.port = 5400;
commandsMap.insert(std::pair<string,Command>("openDataServer",s));
Server is inherent from Command
class Server: public Command{
public:
static map<string,Varinfo> symbolList;
static map<string,Command> commandsMap;
bool stop = false;
int port;
int execute(vector<string> inputs);
static int lstn(int socketfd,sockaddr_in address);
};
and here is command
class Command{
public:
Command();
int execute(vector<string> inputs);
};
and here I'm trying to find the values that I pushed up there, but the object is from class Command and its empty!
auto it = commandsMap.find(commands[index]);
if ( it != commandsMap.end() ) {
index += it->second.execute(commands);
}
note: commands[index] returns a string and when I debug after pushing the object I see it right inside the map, but when I use find iterator it->second returns empty object Command
any ideas? thanks
Update: I think the problem is that the object that the map finds its not a server object, I want to push in the map many types of classes that inherts Command, and each one to run its own execute() and to have its own fields the Command that the map returns is returned as Command Class, it should return as Server
final Question: I want to use a shared pointer as a solution I have classes like Server that inherits from Command, I want to put them inside a map, and then run thier own execute() as shown upthere