Here's a Clone()
implementation for my class:
MyClass^ Clone(){
return gcnew MyClass(this->member1, this->member2);
}
Now I have about 10 classes derived from MyClass
. The implementation is the same in each case. Owing to the fact that I need to call gcnew
with the actual class name in each case, I am required to create 10 nearly identical implementations of Clone()
.
Is there a way to write one single Clone()
method in the base class which will serve all 10 derived classes?
Edit: Is there a way to invoke the constructor of a class via one of it's objects? In a way that will invoke the actual derived class constructor. Something like:
MyClass ^obj2 = obj1->Class->Construct(arg1, arg2);
I'm doing this on C++/CLI but answers from other languages are welcome.