return a NULL iterator?

This is a discussion on return a NULL iterator? within the C++ Programming forums, part of the General Programming Boards category; I have a vector containing a struct of customer_info and a function that searches that vector for a customer name ...

  1. #1
    Master of Puppets rwmarsh's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    96

    return a NULL iterator?

    I have a vector containing a struct of customer_info and a function that searches that vector for a customer name and returns an iterator to that customer. I want to be able to return A Null iterator is no matches are found ( if that is possible ) but I can't get it to work right. Here is what I have
    Code:
    vector<Customer_Info>::const_iterator Customer_Manager::Find_Customer(string name)
    {
        int length = name.size();
        string name2;
        bool match = false;
        int x = 0;
        char selection;
        
        for (int i = 0; i <= (length - 1); i++)
            name[i] = toupper(name[i]);
        
        vector <vector <Customer_Info>::iterator> temp_list;
        vector <vector <Customer_Info>::iterator>::iterator temp_iter;
        vector<Customer_Info>::iterator iter;
        for (iter = customer_list.begin(); iter != customer_list.end(); ++iter)
        {
            name2 = iter->name.substr(0, length);
            if (name == name2)
            {
                temp_list.push_back(iter);
                match = true;
                cout<<x+1 <<")  " <<iter->name <<"   " <<iter->address1 <<endl;
                x++;
            }
        }
        cout<<endl;
        if (x == 0)
            cout<<"No Matching Fields!" <<endl;
        else
            cout<<"Enter Selection";
        cout<<"<0> to Exit ";
    
        while (true)
        {
            cin>>selection;
            cin.ignore();
            if (selection == '0')
            {
                return iter = NULL;
            }
            if (selection > 0 && selection <= (x + 1) )
                return temp_list.at(x);
            cout<<"Incorrect Selection" <<endl;
        };
    }
    at the part marked in red I get this error
    Code:
    155 C:\Dev-Cpp\Dispatch Planner\Customer_Functions.cpp no match for 'operator=' in 'iter = 0' 
     note C:\Dev-Cpp\include\c++\3.4.2\bits\stl_iterator.h:587 candidates are: __gnu_cxx::__normal_iterator<Customer_Info*, std::vector<Customer_Info, std::allocator<Customer_Info> > >& __gnu_cxx::__normal_iterator<Customer_Info*, std::vector<Customer_Info, std::allocator<Customer_Info> > >::operator=(const __gnu_cxx::__normal_iterator<Customer_Info*, std::vector<Customer_Info, std::allocator<Customer_Info> > >&)
    Any Ideas as to what is wrong? Or if you can even do it like that?
    Using DEV-C++ Under Windows XP
    +------------------------------+

    "No! Do, or Do Not. There is no Try..."

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,646
    No, you can't do it that way. An iterator is not a pointer. Try returning customer_list.end() --- the end() method for a standard container actually returns one past the end of the container.

  3. #3
    Master of Puppets rwmarsh's Avatar
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    96
    Yup, Thats what I thought. Ok, I'll go about this a whole different way. Thanx
    Using DEV-C++ Under Windows XP
    +------------------------------+

    "No! Do, or Do Not. There is no Try..."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 02:48 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. Wierd Segmentation Faults on Global Variable
    By cbranje in forum C Programming
    Replies: 6
    Last Post: 02-19-2005, 12:25 PM
  4. Search and Build Tree
    By 1999grandamse in forum C++ Programming
    Replies: 17
    Last Post: 11-14-2002, 01:36 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM

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