Hi,
I have a Blackboard class and an Item class:
void Blackboard::send(std::vector<std::string> msg, std::string to){
std::list<Subscriber*>::iterator p;
for (p = subscribers.begin(); p != subscribers.end(); p++)
{
if ((*p)->getName() == to) //check if sender is subscribed
{
(*p)->update(msg);
}
else{ // reciever is not subscribed
std::cout << "Can not find " << to << "." << std::endl;
}
}
}
virtual void update(std::vector<std::string> msg) { //inherited from class subscriber
if (msg[0] == "throw")
{
quantity--;
use(msg[3]);
}
else
{
std::cout << "[" << msg[0] << "] action not valid!!" << std::endl;
}
}
in main i have: bB->send(msg, msg[1]);
msg is a vector of strings. msg[0] == "use"; msg[1] == "rock"
In console: I wrote :> use rock
and system cout -> [use] action is not valid
and cannot find rock
.
Whats happening? Whys is else
triggered??