Thread: Iterator can't access structure

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Iterator can't access structure

    Code:
    struct OneWord{
    	std::string be1;
    	std::string be2;
    };
    std::vector<OneWord> words;
    std::vector<OneWord>::iterator the_iterator;
    And somewhere:
    Code:
    if(*the_iterator.be1==name){
        return *the_iterator.be1.c_str();
    }
    Errors:
    Code:
    error: 'class __gnu_cxx::__normal_iterator<OneWord*, std::vector<OneWord, std::allocator<OneWord> > >' has no member named 'be1'
    error: 'class __gnu_cxx::__normal_iterator<OneWord*, std::vector<OneWord, std::allocator<OneWord> > >' has no member named 'be1'
    And the errors refer to these lines:
    Code:
    if(*the_iterator.be1==name){
        return *the_iterator.be1.c_str();
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  2. #2
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    What about (*the_iterator).be1 ?

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Or the_iterator->be1 ?
    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. passing structure arrays to functions?
    By bem82 in forum C Programming
    Replies: 3
    Last Post: 10-30-2006, 06:17 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Another Linked List plee
    By Dragoncaster131 in forum C Programming
    Replies: 3
    Last Post: 05-15-2004, 05:40 PM
  4. how to cast a char *mystring to a structure pointer ??
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 03-29-2004, 08:59 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM