In my program I have a list which is a pointer list<COffenceUnit*>* m_attack = nullptr; I initialize this list like that: m_attack = new list<COffenceUnit*>(); in the constructor. At some point in the code I want to send this list to another constructor as a reference. This is the constructor that receives the list:
GameMap::GameMap(const std::list<CDefenceUnit*>* &defenseUnits, const std::list<COffenceUnit*>* &offenseUnits)
{
mGameMap = new int* [GRID_SIZE];
for (int i = 0; i < GRID_SIZE; ++i)
mGameMap[i] = new int[GRID_SIZE];
updateMap(defenseUnits, offenseUnits);
}
However the compiler throws an error that says:
Error C2664 'GameMap::GameMap(const GameMap &)': cannot convert argument 1 from
'std::list<CDefenceUnit *,std::allocator<_Ty>> **' to 'const std::list<CDefenceUnit *,std::allocator<_Ty>> *&'
I can't figure out what am I doing wrong here.
*and&. You are probably trying to pass it like&m_attackto the constructor when you should usem_attack. Please post a minimal reproducible example. Also why do you have a pointer to a list as a member, and not simply a list? And why does the list have pointers in it and not objects? Using pointers for everything is very bad style inc++. Raw pointer should almost always be avoided.'GameMap::GameMap(const GameMap &)'is not a part of the code you are showing. Please post a minimal reproducible example.