Answer by A M for Choose C++ template at runtime
The correct pattern to use here is the "Abstract Factory" pattern.Maybe you can look it up.To give you and idea (and not more), what is possible, I will show you the below code, which even accepts...
View ArticleAnswer by user8143588 for Choose C++ template at runtime
You could use the registry pattern like this:#include <map>#include <functional>#include <string>template< typename T, typename X >using Factory = std::function< T* ( X&...
View ArticleAnswer by n314159 for Choose C++ template at runtime
A possible macro:#include <memory>#include <string>class BaseClass {};class ClassA : public BaseClass { public: std::string label = "ClassA"; explicit ClassA(int /*unused*/) {}};class...
View ArticleAnswer by zerocukor287 for Choose C++ template at runtime
In that case if the class name is equal to the string, you can simplify your code with the following macro:#define STRING_TO_CLASS (className) if(type == "className") return new...
View ArticleChoose C++ template at runtime
Is there any way to achieve the functionality of below code without creating the mapping between strings and classes manually?template<class base, typename T>base* f(const std::string &type,...
View Article
More Pages to Explore .....