【发布时间】:2013-03-20 14:27:15
【问题描述】:
我想做一个模板函数来输出 boost::circular_buffer 的内容。 这是有问题的代码:
template <typename T>
std::ostream& operator<<(std::ostream& os, const boost::circular_buffer<T>& cb){
boost::circular_buffer<T>::const_iterator it;
for(it=cb.begin(); it!=cb.end(); it++){
os << it;
}
os << std::endl;
return os;
}
出现以下错误:
need ‘typename’ before boost::circular_buffer<T>::const_iterator’ because ‘boost::circular_buffer<T>’ is a dependent scope
提前致谢。
【问题讨论】:
-
你有没有读过错误?
-
我认为它与 C++ 错误消息一样清晰和有启发性;-)
-
这是少数几个模板错误之一,让您喜欢编译器的表现力。