Advertisement

can someone explain a debug error plz

Started by June 19, 2002 06:13 PM
2 comments, last by nextgengamer 22 years, 6 months ago
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
Advertisement
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]
thanks for the responses my traverse is taking a function pointer and I just found out that it needs to be a static function so i guess im going to make that function static and use dynamic_cast to call the Move() funtions that correspond to the objects present.

This topic is closed to new replies.

Advertisement