C++: How can I do *this*?
Posted: Mon Mar 04, 2019 2:24 pm
Hi,
I'm trying to do the following C++ template thing:
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 triedbut that doesn't work. VS 2017 complains with 'T::type': dependent name is not a type which is fine, because the compiler can't know that T::type exists.
Could I use the Base class somehow? Any clues?
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?