典型的模板符号 [英] Typical template notations
问题描述
你好,
我是C ++/VC ++(MFC)开发人员.我是STL的新手(不是很新).每当我遇到STL中的任何函数时,由于模板符号的原因,我都很难阅读其原型.
虽然,我对模板的所有类型都很了解,但是却无法理解模板符号.
在这方面的任何帮助将不胜感激.
祝编程愉快.
Hello,
I am C++/VC++(MFC)developer. I am new (not very new) with STL. Whenever I come across any function in STL I find difficult to read its prototype because of template notations.
Though, I know template very well, all the types of templates, but not able to understand template notations.
Any help in this regard will be highly appreciated.
Happy Programming.
推荐答案
STL和模板符号基本上非常简单和标准.他们总是使用相同的样式.
看一下这篇文章:
STL入门指南 [
STL and template notations are basically quite simple and standard; they always use the same style.
have a look at this article :
An Introductory STL tutorial[^]
Max.
也值得通过 ^ ].我认为模板的最大错误是允许使用class
关键字来定义类型(而不是typename
),如下所示:
It''s also worth going through this section[^] on MSDN. I think the biggest mistake with templates was allowing the use of theclass
keyword to define a type (rather thantypename
) as in:
Template < class T >
class MyClass
{
T myVar;
...
其中< class T >
实际上表示T
是一个占位符,当根据模板构建实类时,该占位符将被实类型替换,例如:
where < class T >
actually means that T
is a placeholder which will be replaced by a real type when a real class is built from the template such as:
MyClass<int> mc;
其中所有T
出现的地方都将替换为int<code>
.
where all occurrences of T
will be replaced by int<code>
.
这篇关于典型的模板符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!