Hello.
I don't even know how to explain this, so here i will try to ask in code.
//I have a class that is like this
class WorkerClass
{
public:
std::vector<Unit> &unit1;
std::vector<Unit> &unit2;
void DoStuff();
void SetUnits(std::vector<Unit> &unit1, std::vector<Unit> &unit2);
};
void WorkerClass::DoStuff()
{
//Change data around in unit1
//Change data around in unit2
}
In my case i got a function "DoStuff()" That dosen't want to care about anything except what is unit1 and unit2.
Problem is that unit1 and unit2 constantly change and they are accessed from:
class Unit
{
public:
//Stuff for unit
};
class UnitGroup
{
public:
std::vector<Unit> UnitList;
};
//This is what i will have
std::vector<UnitGroup> UnitGroupList;
std::vector<Unit> UnitList;
//What i will need to do is
WorkerClass::SetUnits( UnitGroupList[Collided_Unit_Group].UnitList[Some_Unit], UnitList[Some_Unit] );
WorkerClass::DoStuff();
//Now UnitGroupList.clear() is called that will clear all data from it.
//Then its populated with unknown amount of units groups, and those unit groups are populated with unknown amount of units
//Then i redo need to call WorkerClass::DoStuff() on new set units
WorkerClass::SetUnits( UnitGroupList[Different_Unit_Group].UnitList[Different_Unit], UnitList[Different_Unit] );
WorkerClass::DoStuff();
// ... repeat
Now the problem is the reference will point to old and new unit and produce poop.
Is using a pointer in this case valid? i mean i am pointing to a vector holding a vector and changing its data is that valid? wont i get access violation?
And if so, what should i do? i am out of ideas...
EDIT:: A huge error in "SetUnits" i don't want to set a single unit i want to set the std::vector of units