plz help me to know..whether this pointer in c++ is public access or private access

plz help me to know..whether this pointer in c++ is public access or private access

Um...what?

THIS pointer (ex this->a=a) in c++ is either public or private scope?

It's a pointer to the object, so while the this pointer itself can be described as private, you can still access the address of the object anywhere the object is in scope.

Maybe if you look at this code you'll see what the this pointer is...

#include <iostream>

class myint
{
  
public:
  
  myint(int val):itsvalue(val) {}
  
  int getitsvalue() const { return itsvalue; }
  void* get_this() const { return (void*)this; }
  
private:
  
  int itsvalue;
  
};

int main(int argc, char**argv)
{
  myint me(1234);
  
  std::cout << me.get_this() << std::endl;//find this pointer value
  std::cout << &me << std::endl;//find the address of me
  
  std::cout << me.getitsvalue() << std::endl;
  
  *(int*)&me = 9999;
  
  std::cout << me.getitsvalue() << std::endl;
  
  return 0;
}
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.