This may not exactly be a beginner question, but can anyone tell me how to pass a pointer to the calling class as a parameter in a function? I know that Java has a this.* command to allow an object to access itself, but I don't know how to do this in C++. I could always pass in the pointer when creating the class, but that's inconvenient and it must be available to the class without me doing that.
/*The function I'm calling. Accepts pointers to two HasPosition class instances, then calculates whether they have collided. I need to be able to call this function from within either of those two classes.*/
bool Coll::GetColl(HasPosition* a, HasPosition* b)
keyword in C++ is the pointer to the current instance of the object. To get the actual object to use you need the dereference character, say for example:
1 2 3 4 5 6 7 8 9 10 11 12 13
class MY
{
public:
MY(int i):i_(i)
{
this->dosomething();
//or
(*this).dosomething();
}
void dosomething(){}
private:
int i_;
}