Click here to Skip to main content
15,308,835 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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;
std::deque<T>::iterator begin() { return B.begin(); }

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;
std::_Deque_iterator<T, std::allocator< std::deque<T> > > begin() { return B.begin(); }

Strange error message:

error C2440: 'initializing' : cannot convert from 'std::_Deque_iterator<_Ty,_Alloc>' to 'std::_Deque_iterator<_Ty,_Alloc>'
Updated 13-Dec-10 19:57pm
JF2015 14-Dec-10 1:34am
Edited to add code formatting.

1 solution

Hi Ted,
Not really understanding why you want to expose that, anyhow this should compile:
typename std::deque<T>::iterator begin()
    return B.begin();


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900