java - How to implement MyClass<T extends OtherClass> in C++? -
can tell me how implement java-code in c++?
public class myclass<t extends otherclass>{ .... }
i've tested in c++:
template<class t, class otherclass> class myclass { public: myclass(); }
but i've error:invalid use of template-name 'myclass' without argument list
greetings
you can use std::is_base_of
in combination static_assert
:
template<class t> class myclass { static_assert( std::is_base_of< otherclass, t >::value, "t not extend otherclass"); public: myclass(); };
(you can, of course, make otherclass
additional template parameter in case need more flexible)
Comments
Post a Comment