C++ 如何修复编译错误:非模板';迭代器1';用作模板
我对嵌套模板类有一些问题。代码在VS2012中编译良好,但在VS2013和gcc 4.2.x中编译失败:C++ 如何修复编译错误:非模板';迭代器1';用作模板,c++,templates,metaprogramming,C++,Templates,Metaprogramming,我对嵌套模板类有一些问题。代码在VS2012中编译良好,但在VS2013和gcc 4.2.x中编译失败: #include <string> namespace utf { class klar{ //my test class public: template <typename octet_iterator > class iterator1 { int n; }
#include <string>
namespace utf {
class klar{ //my test class
public:
template <typename octet_iterator >
class iterator1
{
int n;
};
};
template< typename impl_t, typename utf_t >
class tanga
{
int b;
public:
typedef typename utf_t::iterator1< typename impl_t::iterator > iterator2;
tanga() {
iterator2 i;
}
};
}
typedef utf::tanga< std::string, utf::klar > Hugo;
static const Hugo h;
#包括
名称空间utf{
类klar{//我的测试类
公众:
模板
类迭代器1
{
int n;
};
};
模板
tanga类
{
int b;
公众:
typedef typename utf_t::iterator1iterator2;
tanga(){
迭代器2 i;
}
};
}
typedef-utf::tangaHugo;
静态常数雨果h;
你知道怎么解决这个问题吗?错误是:
error: non-template 'iterator1' used as template typedef typename utf_t::iterator1< typename impl_t::iterator > iterator2;
^
错误:非模板“iterator1”用作模板typedef typename utf_t::iterator1iterator2;
^
您需要告诉编译器,迭代器1
是一个包含以下内容的模板:
typedef typename utf_t::template iterator1< typename impl_t::iterator > iterator2;
typedef typename utf_t::template iterator 1iterator 2;