Problem with deque and vector

This is a discussion on Problem with deque and vector within the C++ Programming forums, part of the General Programming Boards category; Hi, i am trying to compile this code i found Code: ... #include <deque> #include <list> #include <string> #include <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
    21,713
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 07:17 PM
  2. Very slow processing of vectors?
    By Blackroot in forum C++ Programming
    Replies: 35
    Last Post: 02-06-2006, 05: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21