#include <iostream>
using namespace std;
#define PRINT(x) cout << #x " = " << x << endl;

class Object{
public:
	Object():i(5){}
	 int i;;
};

int main() {
	Object o;
	o.i = 5;
	int* p = &(o.i);
	PRINT(*p);

	int Object::* p2m = &Object::i;
	PRINT(o.*p2m);
	return 0;
}

the two PRINT macros produce this:

*p = 5
o.*p2m = 5

could you tell me what the difference is between using them? when should i choose one over another? and why?
Thank you in advance!

Well ordinarily, your data in the class wouldn't be public to begin with.

Making it public defeats the whole purpose of having classes at all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.