我很困難,我盡我所能,但我無法解決它。又一個C++列表問題
我想做到這一點:
list<Enemy> *_myEnemies;
Enemy* _myEnemiesPushBack;
_myEnemiesPushBack = new Enemy;
_myEnemiesPushBack->load("earth.png");
_myEnemiesPushBack->setPos(150, 150);
_myEnemies->push_back(_myEnemiesPushBack); //error here
錯誤:
\init.cpp(41): error C2664: 'void std::list<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'Enemy *' to 'Enemy &&' 1> with 1> [ 1> _Ty=Enemy 1>
] 1> Reason: cannot convert from 'Enemy *' to 'Enemy' 1>
No constructor could take the source type, or constructor overload resolution was ambiguous
謝謝!
你有一個指向敵人的列表,而不是指向敵人的列表。 – 2011-04-16 19:02:33
你不是指指向敵人列表的指針嗎?當我讀到它時,「指向敵人列表」的意思與「指向敵人的列表」的意思相同。 ;) – jalf 2011-04-16 19:09:09
請不要使用這樣的指針,使用智能指針。 – GManNickG 2011-04-16 19:12:42