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

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -