c++ - How to force all derived classes to implement a virtual method? -
Say that you have a base class Note: The problem here is that to apply this method, make intermediate classes (such as The question ends here. If you are curious why do I need it; I have a class Curiously using recurring template fun, you can get something similar: In addition, your Since Dep for a tree of orbits is a virtual method < Code> Dep * Dep :: create () is that I want to implement it by every single leaf class. Is there any way to implement it?
class B: public A: public dep code> A :: Code>) or because they think are those leaf classes, but in fact they are sub-classified.
Reference
master in which the unknown concrete type of
Dep objects are repeated if I
master is repeated, then I
Dep example mail clone. Even after this, I can not catch it (secondly by crashing so badly), because for unclear reasons, people who have more to say than me, in this project
dynamic_cast has been declared unlawful (perhaps it There is a good decision, but still totally different discussions).
template & lt; Typename T & gt; Class Clonable: Public T, Public Department {Private: Clonable & lt; T & gt; (): T () {} Public: stable clonal & lt; T & gt; * Create () {New Clone Eligible & lt; T & gt; (); } Cloning & lt; T & gt; * Clone () {New Clonable Back & lt; T & gt; (* this); }}; Instead of using
deep and using
new MyType instead of
clonable
is clonable & lt; MyType & gt; From to
MyType , you can use the same way you would use the
MyType , except that it is currently in the
Depre :: Clone .
master should not accept an example of type
Dep , but apply it to a
clonal & lt; T & gt; . (Change your function with a simple function template, which implements it.) It guarantees that any
Dep inside the master is correctly implemented
clone Function.
can be cloned & lt; MyType & gt; does not have any public constructor, it can not be inherited, although your actual
MyType is more in heritage and can be used already.
Comments
Post a Comment