有时我看到gcc在使用模板时吐出的一些非常难以理解的错误消息......具体来说,我遇到了一些问题,看似正确的声明引起了非常奇怪的编译错误,通过在"typename"关键字前加上前缀而神奇地消失了声明的开头...(例如,就在上周,我宣布两个迭代器作为另一个模板化类的成员,我必须这样做)...
关于typename的故事是什么?
实际上我用intel编译器编译一些库时遇到了问题.
使用g ++正确编译了相同的库.
问题是由模板引起的.我想要理解的是
**typename**
函数体内的模板函数参数和变量声明的声明
例:
void func(typename sometype){..
...
typename some_other_type;
..
}
Run Code Online (Sandbox Code Playgroud)
编译这种代码产生以下错误(英特尔),(gcc没有声称):我有以下错误
../../../libs/log/src/attribute_set.cpp(415): error: no operator "!=" matches these operands
operand types are: boost::log_st::basic_attribute_set<wchar_t>::iter<'\000'> != boost::log_st::basic_attribute_set<wchar_t>::iter<'\000'>
while (begin != end)
^
detected during instantiation of "void boost::log_st::basic_attribute_set<CharT>::erase(boost::log_st::basic_attribute_set<CharT>::iter<'\000'>, boost::log_st::basic_attribute_set<CharT>::iter<'\000'>) [with CharT=wchar_t]" at line 438
../../../boost/log/attributes/attribute_set.hpp(115): error: no operator "!=" matches these operands
operand types are: boost::log_st::basic_attribute_set<wchar_t>::iter<'\000'> != boost::log_st::basic_attribute_set<wchar_t>::iter<'\000'>
if (it != m_pContainer->end())
Run Code Online (Sandbox Code Playgroud)
我想要理解的是在函数体内使用typename,参数声明.
例:
template< typename CharT >
struct basic_attribute_values_view< CharT >::implementation
{
public:
..
..
void …
Run Code Online (Sandbox Code Playgroud)