I'm having a little trouble with my templated linked list. It has a pubic method that takes in a function pointer as an argument, and passes each element of the list to the function like so:
Code:
template <typename Type>
class CLList
{
public:
void Iterate( void (*pf)(Type &) );
};
template <typename Type>
void CLList<Type>::Iterate( void (*pf)(Type &) )
{
tNode * cur = m_Head;
while(cur)
{
pf(cur->data);
cur = cur->next;
}
}
Some of you have probably seen this done before. Another class of mine has a CLList as a private member, and a void function like so
Code:
class CMngr
{
private:
CLList m_list<CObject *>;
void UpdateObj(CObject * obj);
}
void CMngr::UpdateObj(CObject * obj)
{
obj->Update();
}
In another function of my CMngr class, I have this line:
Code:
m_list.Iterate(UpdateObj);
and my error looks like so:
Code:
cannot convert parameter 1 from 'void (CObject *)' to 'void (__cdecl *)(Type & ) with [ Type=CObject * ]
My first notion was that it does not like taking the reference of a pointer for some reason, and had my Iterate method take a function pointer that passes the argument by value. That did not work either.
My next step is to make an iterator class, but I would like to see if anyone knows why my original idea did not work, and possibly if they know how to make it work.
Thank you all for your time.