Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am getting an unqualified ID error on lines 89 and 96 which, in the code are: Actor.info = attribute; and Actor.entity info -> name

I am getting an unqualified ID error on lines 89 and 96 which, in the code are: Actor.info = attribute; and Actor.entity info -> name = attribute -> name; Can someone help me figure out why? #include #include #include #include #include #include

void tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = " ") { // Skip delimiters at beginning. std::string::size_type lastPos = str.find_first_not_of(delimiters, 0); // Find first "non-delimiter". std::string::size_type pos = str.find_first_of(delimiters, lastPos);

while (std::string::npos != pos || std::string::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(str.substr(lastPos, pos - lastPos)); // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of(delimiters, pos); // Find next "non-delimiter" pos = str.find_first_of(delimiters, lastPos); } } class Actor; class InvItem;

typedef std::map ActorMap; typedef std::vector InvBag; typedef std::vector TokenVector;

std::ostream& operator<<(std::ostream& o,TokenVector v) { for(int i=0; i

typedef struct { int health,manna,stamina,intel;

} VitalStruct;

typedef struct { std::string name, type; } EntityInfo;

std::ostream& operator<<(std::ostream& o,VitalStruct v) { o << "health:" << v.health << std::endl; o << "manna:" << v.manna << std::endl; o << "stamina:" << v.stamina << std::endl; o << "intel:" << v.intel << std::endl; return o; }

class Actor { protected: VitalStruct vitals; InvBag inventory; EntityInfo info; public: VitalStruct get_vitals(); InvBag get_inventory(); EntityInfo set_type(const EntityInfo&); EntityInfo get_type(); EntityInfo set_name(const EntityInfo&); EntityInfo get_name(); void set_inventory(const InvBag&); virtual void speak(const std::string &message)=0; };

class InvItem {

};

InvBag& operator<<(InvBag& bag,InvItem iv) { bag.push_back(iv); return bag; }

EntityInfo Actor::get_type() { return info; }

EntityInfo Actor::set_type(const EntityInfo& attribute) { Actor.info = attribute; } EntityInfo Actor::get_name() { return info; }

EntityInfo Actor::set_name(const EntityInfo& attribute) { Actor.entity info -> name = attribute -> name; }

VitalStruct Actor::get_vitals() { return vitals; }

void Actor::set_inventory(const InvBag& ivbag) { inventory = ivbag; }

InvBag Actor::get_inventory() { return inventory; }

class Monster : public Actor { public: void speak(const std::string& message); };

void Monster::speak(const std::string& message) { std::cout << "Monster: " << message << std::endl; }

class Hero : public Actor { void speak(const std::string& message); };

void Hero::speak(const std::string& message) { std::cout << "Hero: " << message << std::endl; }

class Villager : public Actor { void speak(const std::string& message); };

void Villager::speak(const std::string& message) { std::cout << "Villager: " << message << std::endl; }

int main() { ActorMap actormap; InvBag bag; EntityInfo type; EntityInfo name;

std::ifstream in_file("./characters.txt"); if(in_file.fail()) { std::cout << "Cannot open file"; exit(1); } std::string buf=""; while(!in_file.eof()) { std::getline(in_file,buf); if(buf.at(0) == '-') { break; } TokenVector tokens; tokenize(buf,tokens,":"); std::string name = tokens[0]; std::string type = tokens[1]; if(type == "Hero") { actormap[name] = new Hero(); //set name //set type } else if(type == "Monster") { actormap[name] = new Monster(); } else if(type == "Villager") { actormap[name] = new Villager(); } actormap[name]->speak("I speak"); actormap[name]->get_name(); } /*

actormap["trundle"] = new Monster(); actormap["tim"] = new Hero(); actormap["penelope"] = new Villager(); bag << InvItem(); actormap["trundle"]->set_inventory(bag);

std::cout << actormap["trundle"]->get_vitals();

actormap["trundle"]->speak("I am trundle, prepare to meet your maker!"); actormap["penelope"]->speak("Where's my hero?"); actormap["tim"]->speak("Let's roll!"); */ return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

Analyse the process of new product of development.

Answered: 1 week ago

Question

Define Trade Mark.

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago