STL programming practice five: neo-shape type declaration
Email - ccplusplus@21cn.com
Foreword
STL is a research results in generic programming. In the generic design, the nest-like type, the nest, is a customary method, which uses TypedEF health. "STL programming practice four" we have made some simple introduction to the use of the health word. Here, you said that using TypeDef Guan Jian word in generic design for nest-like types. It is also a supplement to "STL programming practice four", please don't laugh. Welcome to the criticism.
text
Nest-like types are very complicated, in fact, very simple, take an example:
Template
Struct CType
{
TypeDef t value_type; // This is the nest type type declaration
}
Simple! However, it has an important status in generic programming, mainly used to obtain the original type of Template quotes, let's talk about less appropriate examples (Note: Don't say that the syntax is wrong, just means this example has No use, or if there is anything necessary to write, etc.).
Template
Struct CType
{
Typedef T value_type; // Nest-like type declaration
}
Template
Struct CType
{
Typedef T value_type; // Nest-like type declaration
}
......
Template
TypeName CType
FUNC (T T)
{
......
}
......
INT * PI = New Int (10);
INT IRESULT = FUNC
This simple program uses a nest-like type, the letter FUNC hopes to return the original type of the T core (here Int), when the FUNC's template quotes are int * T-type, INT * Therefore, the function of FUNC cannot directly return to Type T. By returning CType
Can you understand? I hope to help everyone, I don't understand or have a mistake, please let me know, thank you first!
2001-11-28 nights