0

For example,

I have a class foo with some member functions..

within some function say..

void foo::someFunction()
{

int pointer = ??????


}

How do I pass a pointer pointing to the object foo?

Can I do that? Or do I have to do it externally?

2 Answers 2

8
foo* pointer = this;

Note that the pointer type should be foo* not int.

Sign up to request clarification or add additional context in comments.

Comments

5

The special pointer named this is available within (non-static) member functions for this purpose. However, it is not assignment compatible to int, but rather has type foo *.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.