【发布时间】:2012-03-20 12:43:31
【问题描述】:
可能重复:
Where and why do I have to put the “template” and “typename” keywords?
我正在使用 g++4.6,我尝试根据所使用的 char 类型对我的类进行模板化,但我的变量不仅是字符,还有这些字符的字符串。所以我尝试了这样的事情:
template<typename T>
class Node
//...
//constructor
Node(std::basic_string<T> str, std::basic_string<T>::iterator it)
{
}
//usage
Node<char16_t> start;
但我明白了
‘std::basic_string<_chart std::char_traits>, std::allocator<_tp1> >::iterator’ 不是类型
当我将构造函数 arg 列表中的第二个 T 替换为 char16_t 时,它会编译。
【问题讨论】:
-
让
typename std::basic_string<T>::iterator it.
标签: c++ templates c++11 stdstring