Pointers to Objects : object pointer « Pointer « C++ Tutorial






#include <iostream>
using namespace std;
   
class cl {
  int i;
public:
  cl(int j) { i=j; }
  int get_i() { return i; }
};
   
int main()
{
  cl ob(88), *p;
   
  p = &ob; // get address of ob
   
  cout << p->get_i(); // use -> to call get_i()
   
  return 0;
}








11.7.object pointer
11.7.1.Pointers to Objects
11.7.2.uses a pointer to access all three elements of array ob after being assigned ob's starting address
11.7.3.assign the address of a public member of an object to a pointer and then access that member by using the pointer
11.7.4.dereferencing the pointer returned by new
11.7.5.array of pointers to objects