[SOLVED] Polymorphism Help
Posted: Tue Apr 13, 2010 9:31 pm
I swear I've done this before and it worked, wtf.. or maybe i'm just tired
test.cpp
Error: (16) 'class Actor' has no member named 'testVar'
Error: (17) 'class Actor' has no member named 'Shoot'
Purpose: I wanna use it in this function, so I can return a generic Actor or a Player
test.cpp
Code: Select all
#include <iostream>
using namespace std;
class Entity {
public:
Entity();
~Entity();
};
class Actor : public Entity {
public:
Actor() : Entity() {}
~Actor() {}
};
class Player : public Actor {
public:
Player() : Actor() {}
~Player() {}
int testVar;
void Shoot() {};
};
int main()
{
Actor* test = new Player();
test->testVar = 0;
test->Shoot();
cin.get();
delete test;
return 0;
}
Error: (17) 'class Actor' has no member named 'Shoot'
Purpose: I wanna use it in this function, so I can return a generic Actor or a Player
Code: Select all
ActorManager TestManager;
Actor* TestActor;
TestActor = TestManager.GetPlayer("TestName");
---
Actor* ActorManager::GetPlayer(const string &name)
{
// Check if the Player is not Already Loaded
map<string, Actor*>::iterator iter = Actors.find(name);
if((Actors.size() < MAX_ACTOR_COUNT) && (iter == Actors.end()))
{
Actor* act = new Player();
act->name = name;
Actors[name] = act;
cout << name << " is new player\n";
}
return Actors[name];
}