Thread: iterator error with typename

  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,268
    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
    28,413
    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.
    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

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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, 01:06 PM
  2. Need Partners (D&D fan preferably)
    By C_ntua in forum Game Programming
    Replies: 44
    Last Post: 11-22-2008, 09: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, 05:05 PM