From 7b64409dfb1e399c7c980fd3227d5c0432c39e6c Mon Sep 17 00:00:00 2001 From: valmat Date: Thu, 19 Jun 2014 00:03:46 +0600 Subject: implementation issue #97 --- include/class.h | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/class.h b/include/class.h index e0316df..cffc7bd 100644 --- a/include/class.h +++ b/include/class.h @@ -201,6 +201,32 @@ public: Class &extends(const Class &base) { ClassBase::extends(base); return *this; } private: + /** + * Method to create the object if it is default constructable + * @param orig + * @return Base* + */ + template + typename std::enable_if::value, Base*>::type + static maybeConstruct() + { + // create a new instance + return new X(); + } + + /** + * Method to create the object if it is not default constructable + * @param orig + * @return Base* + */ + template + typename std::enable_if::value, Base*>::type + static maybeConstruct() + { + // create empty instance + return nullptr; + } + /** * Construct a new instance of the object * @return Base @@ -208,7 +234,7 @@ private: virtual Base* construct() const override { // construct an instance - return new T(); + return maybeConstruct(); } /** @@ -225,7 +251,7 @@ private: } /** - * Method to clone the object if it is copy constructable + * Method to clone the object if it is not copy constructable * @param orig * @return Base* */ -- cgit v1.2.3