Quantcast
Channel: Choose C++ template at runtime - Stack Overflow
Browsing latest articles
Browse All 5 View Live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Choose 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

Browsing latest articles
Browse All 5 View Live




Latest Images