Call constructor of template parameter
问题 Given a templated factory method, I would like to call different constructors based on the constructors the template parameter provides: template<typename T> T* Factory::create() { if (hasOnlyDefaultConstructor<T>()) return new T(); else return new T(this); } Two problems: If T does not have a constructor T(Factory*), then there are compilation problems. How to write hasOnlyDefaultConstructor()? In general I would like the following: template<typename T> T* Factory::create() { if