can someone explain a debug error plz
hi im getting a compile error:
C:\CPP\My Projects\directdraw\m_game.cpp(314) : error C2664: ''traverse'' : cannot convert parameter 1 from ''void (__thiscall Base::*)(class Base *)'' to ''void (__cdecl *)(class Base *)''
There is no context in which this conversion is possible
the code is this:
collide.traverse(Base::Move, true);
Im using a link list that holds many different objs that all inherit from a base class. I want my link list to traverse and call an overloaded Move() for each object individually.
Any help would be appreciated.
thanks
NextGenGamer
You can''t use member functions with traverse. Either make Move static or use STL adapters, such as std::mem_fun.
---visit #directxdev on afternet <- not just for directx, despite the name
1) by passing Base::Move you are passing a function pointer. is this what you want to do?
2) it's waaaaaaaay easier to make a linked list of Base objects and in class Base declare Move as a virtual function. then when you call obj->Move() you will call the outermost implementation of the move funciton. aka polymorphism -> one of the most useful features of an OO language like C++
if 2) didn't make sense go check out a tutorial on Polymorphism like this one:
http://www.cplusplus.com/doc/tutorial/tut4-4.html
-me
[edited by - Palidine on June 19, 2002 7:31:37 PM]
2) it's waaaaaaaay easier to make a linked list of Base objects and in class Base declare Move as a virtual function. then when you call obj->Move() you will call the outermost implementation of the move funciton. aka polymorphism -> one of the most useful features of an OO language like C++
if 2) didn't make sense go check out a tutorial on Polymorphism like this one:
http://www.cplusplus.com/doc/tutorial/tut4-4.html
-me
[edited by - Palidine on June 19, 2002 7:31:37 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement