Exemple d’incrémentation d’un pointeur sur un tableau d’objet

Author:


Download

#include 
using namespace std;

class ClassTest {
  int nombre;
public:
  void set_nombre(int val) {nombre = val;}
  int get_nombre()
  {
   return nombre;
  }
  void afficher_nombre();
};  

void ClassTest::afficher_nombre()
{
  cout << get_nombre() << "n";
}  

main(void)
{
  ClassTest obj[2], *p;  

  obj[0].set_nombre(5);
  obj[1].set_nombre(55);  

  p = &obj[0];
  p->afficher_nombre(); 

  p++;
  p->afficher_nombre(); 

  p++;
  p->afficher_nombre(); 

  return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *