Content deleted Content added
Updated code to C++11 standard |
→Polymorphic copy construction: Modernized code example |
||
Line 210:
<source lang="cpp">
// Base class has a pure virtual function for cloning
class
public:
virtual ~
virtual
};
// This CRTP class implements clone() for Derived
template <typename Derived>
class
public:
return new Derived(static_cast<Derived const&>(*this));
}
protected:
// We make clear Shape Class need to be inherited
Shape() = default;
Shape(const Shape&) = default;
};
class Square : public Shape<Square>{};
class Circle: public Shape<Square>{};
▲// Every derived class inherits from Shape_CRTP instead of Shape
</source>
|