其他分享
首页 > 其他分享> > c – 如何修复编译错误:非模板’iterator1’用作模板[复制]

c – 如何修复编译错误:非模板’iterator1’用作模板[复制]

作者:互联网

参见英文答案 > Where and why do I have to put the “template” and “typename” keywords?                                    6个
我有一个嵌套模板类的问题.代码在VS2012中编译良好,但在VS2013和gcc 4.2.x中失败:

#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;

知道如何解决这个问题吗?错误是:

error: non-template 'iterator1' used as template typedef typename utf_t::iterator1< typename impl_t::iterator > iterator2;
                             ^

解决方法:

您需要告诉编译器iterator1是一个模板:

typedef typename utf_t::template iterator1< typename impl_t::iterator > iterator2;

标签:c,templates,metaprogramming
来源: https://codeday.me/bug/20190831/1773198.html