dimanche 1 mars 2015

Initialization of std::function does not evaluate to a function taking 3 arguments

GameObject class .h + .cpp:



typedef std::function<void(GameObject* triggerobject, GameObject* otherobject, TriggerAction action)> PhysicsCallback;

void GameObject::OnTrigger(GameObject* triggerobject, GameObject* otherobject, TriggerAction action)
{
if (m_OnTriggerCallback)
m_OnTriggerCallback(triggerobject, otherobject, action);
}

void GameObject::SetOnTriggerCallBack(PhysicsCallback callback)
{
m_OnTriggerCallback = callback;
}


Other class:



m_pSphere->SetOnTriggerCallBack(*pCbObj);
m_pSphere->OnTrigger(m_pWallLeft, m_pSphere, GameObject::TriggerAction(0));


I figured to use the OnTrigger() function I had to set m_OnTriggerCallback. When I tried to pass corresponding arguments however I got really stuck. It seems almost impossible to initalize PhysicsCallback without getting compiler errors.


I tried: std::function<void(GameObject* triggerobject, GameObject* otherobject, GameObject::TriggerAction action)> *obj; *obj = (m_pWallRight, m_pSphere, GameObject::TriggerAction(0));


But no luck. *obj doesn't accept any arguments. These following lines give the same errors:



GameObject::PhysicsCallback *pCbObj; = new GameObject::PhysicsCallback(new std::function<void()>()); //term does not evaluate to a function taking 3 arguments
GameObject::PhysicsCallback *pCbObj = new GameObject::PhysicsCallback((m_pWallRight, m_pSphere, GameObject::TriggerAction(0)));


And this line *pCbObj = GameObject::PhysicsCallback(m_pWallRight, m_pSphere, GameObject::TriggerAction(0));gives this intellisense error: http://ift.tt/1Dqzbpn


I'm really confused, how to use the SetOnTriggerCallBack function?


Aucun commentaire:

Enregistrer un commentaire