/ ************************************************** ****************************** * SGI * STL is the work of STL's parent Alexander Stepanov and STL Matt Austern et al., It is today * * is the most famous, the best STL implementation version, all source code and instructions documents can be used from www.sgi.com/stl/ * * * * is our best model. But well known, STL use A large number of complex C features, * * Plus the STL itself is complex and huge, making reading code itself a very difficult job. The following text * * Word is some of my experience and guess in learning STL I hope to help everyone, and I hope to get * * Get everyone's criticism and finger, so that we will increase our joint increase. * * Myan * ******************* *********************************************************** *********** /
In SGI * STL source code, TypeName This new C keyword can be used to use it everywhere. Many people who have learned C before, in fact, its conventional usage is simple: in the declaration template function or template At class, traditional ways: template
You can also write Template
First see a SGI * STL source code, taken from STL_ITerator.h
1: template
The puzzling part is in the fourth line. Please think about it before watching my explanation, I dare not guarantee the correctness and comprehensiveness of the explanation below.
Explanation: I think TypeName is: notify the compiler, the stupid thing behind TypenAme is a type, not something else.
Example: // Tpname.cpp # include
Using namespace std;
Template
Template
INT main () {typef ape; type> twoint_type; twoint_type :: two_value_type i; int J; if (typeid (i) == typeid (j)) // If i is an INT variable Cout << "Right!" << Endl; // Print Right Return;} // ~ TPNAME.CPP
The above examples were compiled with G 2.91 under Linux. The result was printed. But if the * 1 line of the note number is removed, the comment * 2 line, then compile the error, the compiler doesn't know about :: One_Value_type Why, usually. After the type in the template class parameter, it will only reveal the true body, but this CTWO class is biased to rely on an existing CONE template class, I hope to pre-guarantee ctwo :: two_value_type and cone :: one_value belongs to the same type, This is, please ask TypeName to go out, tell the compiler, the back :: One_Value_type is a name of the type already existing, so the compiler can work smoothly.