Accessing member function from list

ok heres what I'm trying to do, first I make a class

1
2
3
4
5
6
class Name
{
//stuff
     memberfunction () {return something;}
//more stuff
};


then I add newly created objects to a list

1
2
3
4
list<Name> = listofnames;
Name bob,shirely;
listofnames.push_back(bob);
listofnames.push_back(shirely);


now I want to walk through the list and get something from each object from the list and I am not sure where to start on that.
Last edited on
Start at the beginning and when you come to the end, stop.
my list is in namespace functions and is named currentfunctions and I get the error


error: no match for 'operator=' in 'it = Functions::currentfunctions.std::list<_Tp, _Alloc>::begin [with _Tp = Function, _Alloc = std::allocator<Function>]'|

heres the code:

the class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Function{
    std::wstring name, function, units;
    public:
    Function(std::wstring,std::wstring,std::wstring);
    std::wstring getname(){ return name;}
    std::wstring getfunction(){ return function;}
    std::wstring getunits(){ return units;}
    Function operator = (Function);
};

Function::Function(std::wstring newname, std::wstring newfunction, std::wstring newunits){
    name = newname;
    function=newfunction;
    units=newunits;
}
Function Function::operator=(Function param){
    Function temp(param.getname(),param.getfunction(),param.getunits());
    return temp;
}


the list:

1
2
3
namespace Functions{
list<Function> currentfunctions;
}


the walkthrough:
1
2
3
4
list<Function>::iterator it;
for (it=Functions::currentfunctions.begin;it!=Functions::currentfunctions.size();it++){
       wcout << it.name << it.function <<endl;
}

Last edited on
You forgot the parenthesis. begin()
Also you can't compare an iterator against an integer it!=Functions::currentfunctions.size()

wcout << it->name << it->function <<endl; //you'll need to dereference the iterator But that members are private
It worked thank you ne555
Topic archived. No new replies allowed.