M
Martin Magnusson
Hi!
I have a class with a private member which is a pointer to an abstract
class, which looks something like this:
class Agent
{
public:
void Step( Base* newB );
private:
Base* previousB;
};
For each time Step() is called, it should copy the contents of newB to
previousB, as the next time Step() is called, it needs to do stuff with
previousB. Now, how can I do that without knowing what derived class
newB actually is? Just copying the pointer won't work, since what it
points to may well change between calls. Can I use memcpy in some way,
or do I need to make a derived class of Agent which uses a "Derived
previousD;" instead of "Base* previousB;"?
/ martin
I have a class with a private member which is a pointer to an abstract
class, which looks something like this:
class Agent
{
public:
void Step( Base* newB );
private:
Base* previousB;
};
For each time Step() is called, it should copy the contents of newB to
previousB, as the next time Step() is called, it needs to do stuff with
previousB. Now, how can I do that without knowing what derived class
newB actually is? Just copying the pointer won't work, since what it
points to may well change between calls. Can I use memcpy in some way,
or do I need to make a derived class of Agent which uses a "Derived
previousD;" instead of "Base* previousB;"?
/ martin