Hi - I'm working with the iphone in Objective-C, but this question really applies to C++.
I've tried to implement a b2ContactListener subclass like this, in the header file:
and the source file:
However, when I compile, I'm getting quite a few errors:
Am I implementing the sublcass incorrectly? Which file do I need to include to create a subclass of b2ContactListener?
I would have liked to have done it in Objective-C, but I'm forced to use C++ for the contact listener, which I'm quite unfamiliar with.
Cheers,
TheSamuraiElephant
I've tried to implement a b2ContactListener subclass like this, in the header file:
Code:
#include "../Box2D-2.0.2/Source/Dynamics/Contacts/b2Contact.h"
class PokContactListener : public b2ContactListener
{
public:
void Add(const b2ContactPoint* point)
{
// handle add point
}
void Persist(const b2ContactPoint* point)
{
// handle persist point
}
void Remove(const b2ContactPoint* point)
{
// handle remove point
}
void Result(const b2ContactResult* point)
{
// handle results
}
};
class PokContactListener : public b2ContactListener
{
public:
void Add(const b2ContactPoint* point)
{
// handle add point
}
void Persist(const b2ContactPoint* point)
{
// handle persist point
}
void Remove(const b2ContactPoint* point)
{
// handle remove point
}
void Result(const b2ContactResult* point)
{
// handle results
}
};
and the source file:
Code:
#include "PokContactListener.h"
#include "../Box2D-2.0.2/Source/Dynamics/Contacts/b2Contact.h"
void PokContactListener::Add(const b2ContactPoint* point){
}
void PokContactListener::Persist(const b2ContactPoint* point){
}
void PokContactListener::Remove(const b2ContactPoint* point){
}
void PokContactListener::Result(const b2ContactPoint* point){
}
#include "../Box2D-2.0.2/Source/Dynamics/Contacts/b2Contact.h"
void PokContactListener::Add(const b2ContactPoint* point){
}
void PokContactListener::Persist(const b2ContactPoint* point){
}
void PokContactListener::Remove(const b2ContactPoint* point){
}
void PokContactListener::Result(const b2ContactPoint* point){
}
However, when I compile, I'm getting quite a few errors:
Code:
Line Location b2Contact.h:31: error: forward declaration of 'struct b2ContactListener'
Line Location PokContactListener.cpp:4: error: redefinition of 'void PokContactListener::Add(const b2ContactPoint*)'
Line Location PokContactListener.cpp:8: error: redefinition of 'void PokContactListener::Persist(const b2ContactPoint*)'
Line Location PokContactListener.cpp:12: error: redefinition of 'void PokContactListener::Remove(const b2ContactPoint*)'
Line Location PokContactListener.cpp:16: error: prototype for 'void PokContactListener::Result(const b2ContactPoint*)' does not match any in class 'PokContactListener'
Line Location PokContactListener.h:4: error: invalid use of incomplete type 'struct b2ContactListener'
Line Location PokContactListener.h:6: 'void PokContactListener::Add(const b2ContactPoint*)' previously defined here
Line Location PokContactListener.h:11: 'void PokContactListener::Persist(const b2ContactPoint*)' previously defined here
Line Location PokContactListener.h:16: 'void PokContactListener::Remove(const b2ContactPoint*)' previously defined here
Line Location PokContactListener.h:21: error: candidate is: void PokContactListener::Result(const b2ContactResult*)
Line Location PokContactListener.cpp:4: error: redefinition of 'void PokContactListener::Add(const b2ContactPoint*)'
Line Location PokContactListener.cpp:8: error: redefinition of 'void PokContactListener::Persist(const b2ContactPoint*)'
Line Location PokContactListener.cpp:12: error: redefinition of 'void PokContactListener::Remove(const b2ContactPoint*)'
Line Location PokContactListener.cpp:16: error: prototype for 'void PokContactListener::Result(const b2ContactPoint*)' does not match any in class 'PokContactListener'
Line Location PokContactListener.h:4: error: invalid use of incomplete type 'struct b2ContactListener'
Line Location PokContactListener.h:6: 'void PokContactListener::Add(const b2ContactPoint*)' previously defined here
Line Location PokContactListener.h:11: 'void PokContactListener::Persist(const b2ContactPoint*)' previously defined here
Line Location PokContactListener.h:16: 'void PokContactListener::Remove(const b2ContactPoint*)' previously defined here
Line Location PokContactListener.h:21: error: candidate is: void PokContactListener::Result(const b2ContactResult*)
Am I implementing the sublcass incorrectly? Which file do I need to include to create a subclass of b2ContactListener?
I would have liked to have done it in Objective-C, but I'm forced to use C++ for the contact listener, which I'm quite unfamiliar with.
Cheers,
TheSamuraiElephant