Exemple d’initialisation d’un tableau d’objet d’une classe

Author:

classe
Download


#include 
using namespace std;

class ClasseInt {
  int nombre;
public:

 // Constructeur de la classe
  ClasseInt(int n)
  {
     nombre = n;
  }
  // Lire le paramètre du constructeur de type int
  int getInt()
  {
     return nombre;
  }
};

int main()
{
  ClasseInt val[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int i;

  for(i = 0; i <9; i++)
     cout << val[ i ].getInt() << ' ';

  cout << endl;

  return 0;
}

Leave a Reply

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