【问题标题】:Print boost::circular_buffer<T>打印 boost::circular_buffer<T>
【发布时间】: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++ templates boost


【解决方案1】:

请下次看看错误信息,哪里错了就很清楚了:

在 boost::circular_buffer::const_iterator' 之前需要“typename”,因为“boost::circular_buffer”是一个依赖范围

所以,是的,按照错误消息中的说明进行操作:

typename boost::circular_buffer<T>::const_iterator it;

您可以阅读相关名称in this thread

【讨论】:

  • 感谢有关依赖名称的链接。
猜你喜欢
  • 2015-08-08
  • 1970-01-01
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多