我创建了一个具有双端队列对象的模板类.我很少希望能够访问std :: deque :: iterator对象.但是,我一直无法获得一个非常简单的示例来工作...关于如何解决它的任何想法? 我有一个使用受保护的和私有继承的示例,但是出于性能原因和通用性考虑,如果我的类具有多个双端队列/向量,我更喜欢分层.此外,通过分层,我隐藏了更多的实现细节... 第一次尝试
I created a template class that has a deque object. I infrequently want to be able access the std::deque::iterator object. However, I have been unable to get a very simple example to work... Any ideas how to fix it? I have an example working now using protected and private inheritance, but I would prefer layering for performance reasons and generality if my class has more than one deque/vector. Moreover, with layering, I had hide more implementation details... 1st try
template<typename T> class XYZ { std::deque<T> B; .... public: std::deque<T>::iterator begin() { return B.begin(); } );警告C4346:``std :: deque< Task> :: iterator'':从属名称不是类型 错误C2146:语法错误:标识符开始"之前缺少;" 第二次尝试
warning C4346: ''std::deque<Task>::iterator'' : dependent name is not a type error C2146: syntax error : missing '';'' before identifier ''begin'' 2nd try
template<typename T> class XYZ { std::deque<T> B; .... public: std::_Deque_iterator<T, std::allocator< std::deque<T> > > begin() { return B.begin(); } };错误消息: 错误C2440:``正在初始化'':无法从``std :: _ Deque_iterator< _Ty,_Alloc>''转换为``std :: _ Deque_iterator< _Ty,_Alloc>''
Strange error message: error C2440: ''initializing'' : cannot convert from ''std::_Deque_iterator<_Ty,_Alloc>'' to ''std::_Deque_iterator<_Ty,_Alloc>''
推荐答案泰德, 不太了解为什么要公开它,无论如何都应编译: Hi Ted, Not really understanding why you want to expose that, anyhow this should compile: typename std::deque<T>::iterator begin() { return B.begin(); }
欢呼声, AR
cheers, AR