Hacker News new | past | comments | ask | show | jobs | submit login

Extend a template and specialize it for some type. Extend the template again and specialize it for some other type.

The two resulting derived classes are not the same, and you cannot have a function that accepts the base template with a wild card type and pass both types into it.

In Java, you can do: void myFunc(List<?> list); and all List objects with any type can be accepted by this method, in addition any class that extended List can also be accepted into this method, such as ArrayList<?> or whatever.

As far as I've seen, this is impossible in C++, unfortunately.




Why not

    template<typename T>
    void my_func(std::vector<T>& vec);
?

The reference (or use a pointer, if you want) ensures that derived types can be passed, and the template allows for any parameterization to be used.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: