GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing cpppatterns.com — Virtual constructor - C++ Patterns
← Patterns
Virtual constructor
This pattern is licensed under the CC0 Public Domain Dedication.
Requires
c++11
or newer.
IntentCreate a copy of an object through a pointer to its base type. DescriptionYou can’t copy an object unless you know its static type, because the compiler must know the amount of space it needs to allocate. Therefore we can’t copy an object of derived type directly through a pointer to its base. The virtual constructor idiom is a technique for delegating the
act of copying the object to the derived class through the use of
virtual functions. To demonstrate, we declare a virtual member
function of Now, consider that we are given a Note: It is not possible to implement the virtual constructor
idiom as-is with smart pointers, as derived virtual member
functions must have covariant return types. One workaround
is for Share | ||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |