class Turn_Manager
{
private:
std::vector<std::shared_ptr<iUnit>> combatUnits;
public:
Turn_Manager();
void init(std::vector<std::shared_ptr<iUnit>> activeUnits);
};
Turn_Manager::Turn_Manager()
{
}
void Turn_Manager::init(std::vector<std::shared_ptr<iUnit>> activeUnits)
{
combatUnits = activeUnits;
//std::vector<std::shared_ptr<iUnit>> test = activeUnits;
}
The error occurs when init is called. Here is the function from which it is called:
void Battle_Map::fillUnits()
{
std::vector<std::shared_ptr<Character>> chars = player->getChars();
units.insert(units.end(), chars.begin(), chars.end());
units.insert(units.end(), enemies.begin(), enemies.end());
turnManager->init(units);
}
When I run my program, I'm getting an access violation on combatUnits. The debugger shows that within the scope of the init method, activeUnits is fine. In contains correct and accurate data. combatUnits on the other hand shows up as unreadable, and that makes no sense to me. Furthermore, when I run the program with the commented out line above instead of the combatUnits line, everything works correctly and test shows accurate and correct data (though, obviously, in goes out of scope immediately afterwards and is thus useless).
I'm just very confused as the why declaring a vector locally rather than as a class member would make any difference in this context...
Furthermore, I was just starting to implement the Turn_Manager class, what is posted above is currently the complete contents of the class. I created it in order to isolate certain functionality out of the Battle_Map class (which is too big and needs to have its responsibilities take down a few pegs). The functionality in question worked as intended when it was contained within Battle_Map.