I'm trying to do the following C++ template thing:
Syntax: Select all
template <class T>
T *do_stuff(const char *key, T::type default_value, bool required = false)
{
Base *o = new T(key, default_value, required);
...
}
Base constructor does not have the default_value parameter, but T must have it, so I can't use polymorphism.
I'm interested in how I could do the T::type thing. I know this is possible, but I don't know how to do it. I tried
Syntax: Select all
// within T type
using type = int;
Could I use the Base class somehow? Any clues?