Say I had 2 classes A and B, where A is a pure abstract class with a pure virtual function and B inherits from A and implements the pure virtual function. If I then have a function g() that I want to pass any instance of a subclass of A by value to (so I could mutate it without changing the original instance), how would you do that?
I know that the following code does not fit my purposes:
void g(A myObject) {} //doesn't work since A contains a pure virtual function
void g(A* myObject) {} //code compiles, but changes the original instance
Would I just copy the instance and make a pointer to it and pass into a function like above? Or is there a cleaner way to do this?