iterator error with typename

This is a discussion on iterator error with typename within the C++ Programming forums, part of the General Programming Boards category; I am trying to compile this snippet of code. The error comes from the Code: typename std::vector<T>::const_iterator fileIterator; But I ...

  1. #1
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926

    iterator error with typename

    I am trying to compile this snippet of code. The error comes from the
    Code:
          typename std::vector<T>::const_iterator fileIterator;
    But I am confused why I need typename and what the problem is. Here are the errors I am getting
    Code:
    interface.hpp:37: error: no match for ‘operator=’ in ‘fileIterator = ((interface<int>*)this)->interface<int>::files.std::vector<_Tp, _Alloc>::begin [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]()’
    /usr/include/c++/4.1.3/bits/stl_iterator.h:634: note: candidates are: __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >& __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >::operator=(const __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >&)
    interface.hpp:37: error: no match for ‘operator!=’ in ‘fileIterator != ((interface<int>*)this)->interface<int>::files.std::vector<_Tp, _Alloc>::end [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]()’
    chunker.cpp:13:   instantiated from here
    interface.hpp:38: error: no match for ‘operator+’ in ‘((interface<int>*)this)->interface<int>::files.std::vector<_Tp, _Alloc>::begin [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >] + fileIterator’
    Code:
    template <class T>
    void interface<T>::chunk(size_t block_size){
          //just creates one big chunk for now also reads at one large interval
          char *inbuff;
          int size;
          T in;
          typename std::vector<T>::const_iterator fileIterator=files.begin();
          for(fileIterator=files.begin();fileIterator!=files.end();fileIterator++){
             saga::filesystem::file f(saga::url(files.begin+fileIterator), saga::filesystem::Write | saga::filesystem::Create);
             while(f >> in){
                std::cout << in << std::endl;
             }
          }
    Thanks for your help :-D

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I hate reading template compile errors, but it looks like you are trying to use a vector<int>::iterator on a vector<string>.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    But I am confused why I need typename and what the problem is.
    std::vector<T> is a typename. But std::vector<T>::const_iterator could be a non-type name, e.g., a member variable. Where templates are involved, the C++ Standard requires that this ambiguity be resolved by the use of typename. Without it, the name is assumed to be a non-type name.
    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

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And it has nothing to do with your problem.


    What's the declaration of files?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Use of a class in place of main( )?
    By Sebastiani in forum C++ Programming
    Replies: 15
    Last Post: 12-10-2008, 12:06 PM
  2. Need Partners (D&D fan preferably)
    By C_ntua in forum Game Programming
    Replies: 44
    Last Post: 11-22-2008, 08:21 AM
  3. typedef and typename
    By VirtualAce in forum C++ Programming
    Replies: 16
    Last Post: 07-17-2008, 08:11 PM
  4. explanation of typename keyword?
    By 7stud in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2006, 04:05 PM

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