C++ Template: What happens if we put wrong thing in our template class -


c++ templates allow put whatever in our objects template arguments. however, if our template arguments use functions/variables belong types, how check?

template<typename bartype>rguments  class foo {  public:       foo() { bar = new bartype() }  private:       bartype * bar;  }  foo<bar> … 

bartype derived bar superclass.

what happens if invoke functions belong bar in our foo class? happens if pass non-bartype? have anyway check?

you compile-time error if templated code makes reference members actual parameter doesn't provide when try instantiate template. don't worry, won't able break anything.

think of templates code-generation mechanism. whether generated code makes sense can determined when try it.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -