template inheritance c++ -


I am a new programmer in c ++ and for the first time I am using a template.

I have an abstract class and the second class increases it. However, all protected members of the abstract category are not recognized by other classes:

class0.h:

  template & lt; Class T & gt; Class class0 {protected: char p; Public: four together (); }; ** class1.h ** template & lt; Square T & gt; Class 1 class: Public Class 0 & lt; T & gt; {Public: Zero Printers (); }; Template & lt; Class T & gt; Zero square 1 & lt; T & gt; :: printChar () {cout & lt; & Lt; P & LT; & Lt; Endl; // p was not declared in this scope  

thanks a great week =)

Why is this happening with the lookup rules of templates?

P is not a dependent expression because it is just an identifier and nothing depends on the template parameter. This means that base squares that rely on template parameters will not be found to resolve the name p . To solve this problem, you need to use something that depends on the template parameter. This-> to use.

For example.

  cout & lt; & Lt; This- & gt; P & lt; & Lt; Endl;  

Comments