Hello Everyone,
I have a problem I am currently facing and I'm wondering if the community could help me out. I find it's probably easier to explain with an example.
struct Base
{
};
struct Derived : public Base
{
Derived(float newX) : x(newX)
{
}
float x;
};
struct Unrelated : public Base
{
Unrelated(char val) : v(val)
{
}
char v;
}
...
// How to copy the data that's in mBaseArray into another struct?
// Don't want pointer copy as it's not thread safe.
// Below is a very simple example.
Module1
-----------
class Module1
{
...
Array<Base*> mBaseArray;
};
- mBaseArray is populate in some fashion. Notice the use of polymorphism here.
mBaseArray.push_back(new Derived(10));
mBaseArray.push_back(new Unrelated('c'));
... Some sync point here
... After this point, I want to copy the information that is in mBaseArray into Module2's mWorkingArray.
Module2
-----------
class Module2
{
...
Array<Base*> mWorkingArray;
};
- Want to copy the data from mBaseArray into Module2's own array.
- Copied data from mBaseArray without the use of pointers. Want only data.
- Module2 contains a similar declaration to mBaseArray.
Is there a way to accomplish this? Or is there some other method that will solve this problem?
If there are better ways of doing what I'm trying to accomplish, I am more than welcome to suggestions.
Thanks.