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

Popular posts from this blog

mongodb - Struggling to get ordered results from the last retrieved article, given array of elements to search in -

c# - Pausing a storyboard on TabItem mouse over -

c# - Attribute value in root node of xml Linq to XML -