湖南有什么特色美食:templete<class Record>这样的东西怎么用的啊?有什么用什么意思啊?

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 14:48:24

这是模板啊!

template
C++ Specific —>

template < [typelist] [, [ arglist ]] > declaration

The template declaration specifies a set of parameterized classes or functions.

The template parameter list is a comma-separated list of types (in the form class identifier or typename identifier) or a non-type to be used in the template body. The declaration field must be a declaration of a function or class.

You can instantiate a class template much like you would instantiate a normal class, but include the template arguments within angle brackets. No special syntax is required to call a function template.

See Also Template Topics

END C++ Specific

Example

// Example of the template keyword
template <class T, int i> class TestClass {
public:
char buffer[i];
T testFunc(T* p1 );
};

template <class T, int i>
T TestClass<T,i>::testFunc(T* p1) {
return *(p1++)
};

// To create an instance of TestClass
TestClass<char, 5> ClassInst;
引自MSDN
如果你没看过模板中的class关键字的话,那么你应当在学习模板时学过typename关键字吧,这两个关键字的作用是一样的.只是在使用class关键字时可能会和类的声明中的那个class搞混了,后来才改为typename关键字的.