Thread: Problem with deque and vector

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    4

    Problem with deque and vector

    Hi, i am trying to compile this code i found

    Code:
    ...
    #include <deque>
    #include <list>
    #include <string>
    #include <vector>
    ...
    Code:
    ...
    template <class T>
    		EmStream&				operator >>		(deque<T>& container)
    								{
    									Int32	numElements;
    									*this >> numElements;
    
    									container.resize (numElements);
    
    									deque<T>::iterator iter = container.begin ();
    									while (iter != container.end ())
    									{
    										*this >> *iter;
    										++iter;
    									}
    
    									return *this;
    								}
    
    		template <class T>
    		EmStream&				operator >>		(list<T>& container)
    								{
    									Int32	numElements;
    									*this >> numElements;
    
    									container.resize (numElements);
    
    									list<T>::iterator	iter = container.begin ();
    									while (iter != container.end ())
    									{
    										*this >> *iter;
    										++iter;
    									}
    
    									return *this;
    								}
    ...
    And I get this error
    Code:
    ./../SrcShared/EmStream.h: In member function `EmStream& EmStream::operator>>(std::deque<T, std::allocator<_CharT> >&)':
    ./../SrcShared/EmStream.h:93: error: expected `;' before "iter"
    ./../SrcShared/EmStream.h:94: error: `iter' was not declared in this scope
    ./../SrcShared/EmStream.h: In member function `EmStream& EmStream::operator>>(std::list<T, std::allocator<_CharT> >&)':
    ./../SrcShared/EmStream.h:111: error: expected `;' before "iter"
    ./../SrcShared/EmStream.h:112: error: `iter' was not declared in this scope
    ./../SrcShared/EmStream.h: In member function `EmStream& EmStream::operator>>(std::vector<T, std::allocator<_CharT> >&)':
    ./../SrcShared/EmStream.h:129: error: expected `;' before "iter"
    ./../SrcShared/EmStream.h:130: error: `iter' was not declared in this scope
    ./../SrcShared/EmStream.h: In member function `EmStream& EmStream::operator<<(const std::deque<T, std::allocator<_CharT> >&)':
    ./../SrcShared/EmStream.h:146: error: expected `;' before "iter"
    ./../SrcShared/EmStream.h:147: error: `iter' was not declared in this scope
    I do not completely understand what this does, but i have kind of an idea.
    Last edited by jdc18; 05-01-2007 at 01:38 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You probably need to use the typename keyword before std::deque<T>::iterator, e.g.,
    Code:
    typename std::deque<T>::iterator iter = container.begin();
    Incidentally, this is just a C++ question, not a Linux programming question, so I shall move it appropriately.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    4
    I fixed it
    just had to add typename before

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iterator for deque
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 03-06-2008, 08:17 PM
  2. Very slow processing of vectors?
    By Blackroot in forum C++ Programming
    Replies: 35
    Last Post: 02-06-2006, 06:36 PM
  3. Help with accessing vector variables
    By earth_angel in forum C++ Programming
    Replies: 12
    Last Post: 06-28-2005, 09:48 AM
  4. File access question
    By Imperito in forum C++ Programming
    Replies: 5
    Last Post: 04-19-2002, 11:37 AM