uses a pointer to access all three elements of array ob after being assigned ob's starting address : object pointer « Pointer « C++ Tutorial






#include <iostream>
using namespace std;
   
class cl {
  int i;
public:
  cl() { i=0; }
  cl(int j) { i=j; }
  int get_i() { return i; }
};
   
int main()
{
  cl ob[3] = {1, 2, 3};
  cl *p;
  int i;
   
  p = ob; // get start of array
  for(i=0; i<3; i++) {
    cout << p->get_i() << "\n";
    p++; // point to next object
  }
   
  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