XXX is parsed as a non-type, but instantiation yields a type 错误解决办法

最近在写程序的时候遇到了XXX is parsed as a non-type, but instantiation yields a type 的错误。程序上下文如下

template<typename FullKey,// base containe
         typename PolicyTraits
         >
class container_with_policy
{
private:
	FullKey m_cache;//initialize first

public:
	struct container_element
	{
		typename PolicyTraits::policy_hook_type  policy_hook_;
		typename FullKey::iterator m_iterator;
		typedef typename PolicyTraits::template container_hook<container_element>::type PolicyHook;
		typename FullKey::iterator& operator&(){return m_iterator;};
		container_element& operator=(typename FullKey::iterator& it)
		{
			m_iterator=it;
			return *this;
		}

		container_element(){};
		container_element(const typename FullKey::iterator& it):m_iterator(it){}


	};

	typedef typename FullKey::iterator iterator;
	typedef typename FullKey::const_iterator const_iterator;
	typedef typename PolicyTraits::template policy<
			FullKey,
			container_element,
			container_element::PolicyHook >::type policy_container;
	typedef typename FullKey::value_type base_element_type;
///
	container_with_policy();
	~container_with_policy();
};
<pre name="code" class="cpp">container_element::PolicyHook >::type policy_container;

 这一行里,编译器提示 

error: dependent-name ‘ns3::ndn::container_with_policy<FullKey, PolicyTraits>::container_element:: PolicyHook’ is parsed as a non-type, but instantiation yields a type    container_element::PolicyHook >::type policy_container;

大意是说PolicyHook在编译器看来不是一个类型,但是却要它作为一个类型来使用。

但是没理由啊,

typedef typename PolicyTraits::template container_hook<container_element>::type PolicyHook;

这里已经把PolicyHook作为一个typedef了。

仔细看看,原来凡是typedef的内容,在使用的时候,要在前面加上typename, 否则编译器搞不清楚这个到底是你写错了还是真的有这个类型。

修改方法:

把container_element::PolicyHook前面添加typename,改成typename container_element::PolicyHook即可,结果错误消失了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值