An object is polymorphic when its specific type may vary.
The types a specific value may take, is called class.

It is trivial to copy an object if its type is known:

int x;
int y = x;
Here x is not polymorphic, so y is declared of same type (int) as x.
But if the specific type of x were unknown, then y could not be declared of any specific type.

The task: let a polymorphic object contain an instance of some specific type S derived from a type T.
The type T is known.
The type S is possibly unknown until run time.
The objective is to create an exact copy of such polymorphic object (not to create a reference, nor a pointer to).
Let further the type T have a method overridden by S.
This method is to be called on the copy to demonstrate that the specific type of the copy is indeed S.

#include <iostream>
 
class T
{
public:
  virtual void identify() { std::cout << "I am a genuine T" << std::endl; }
  virtual T* clone() { return new T(*this); }
  virtual ~T() {}
};
 
class S: public T
{
public:
  virtual void identify() { std::cout << "I am an S" << std::endl; }
  virtual S* clone() { return new S(*this); }
};
 
class X // the class of the object which contains a T or S
{
public:
  // by getting the object through a pointer to T, X cannot know if it's an S or a T
  X(T* t): member(t) {}
 
  // copy constructor
  X(X const& other): member(other.member->clone()) {}
 
  // copy assignment operator
  X& operator=(X const& other)
  {
    T* new_member = other.member->clone();
    delete member;
    member = new_member;
  }
 
  // destructor
  ~X() { delete member; }
 
  // check what sort of object it contains
  void identify_member() { member->identify(); }
 
private:
  T* member;
};
 
int main()
{
  X original(new S);      // construct an X and give it an S,
  X copy = original;      // copy it,
  copy.identify_member(); // and check what type of member it contains
}