您的位置:首页 > 其它

dependent-name ‘xxx::yyy’ is parsed as a non-type, but instantiation yields a type

2015-07-10 13:18 816 查看
简言之,就是说你该用typename的地方没用typename,如以下代码

template<class Cont> void frontInsertion(Cont& ci) {
copy(a, a + sizeof(a)/sizeof(Cont::value_type),
front_inserter(ci));
copy(ci.begin(), ci.end(),
ostream_iterator<typename Cont::value_type>(
cout, " "));
cout << endl;
}


报错:

error: dependent-name ‘Cont:: value_type’ is parsed as a non-type, but instantiation yields a type

note: say ‘typename Cont:: value_type’ if a type is meant

解决办法:

在第2行的Cont::value_type改为typename Cont::value_type即可

备注:

上面的代码用MS VisualStudio自带的编译器编译不会报错,但是GCC会报错。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: