Iterator can't access structure

This is a discussion on Iterator can't access structure within the C++ Programming forums, part of the General Programming Boards category; 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: ...

  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,892
    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, 05: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, 07:59 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM

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