Initialisation d’un tableau d’objet de type ‘char’

Author:

classe
Download

#include 
using namespace std;

class ClasseChar
 {
 char ch;
public:
	//Constructeur de la classe
  ClasseChar(char c)
  {
     ch = c;
  }
  char get_ch()
  {
     return ch;
  }
};

int main()
{

 // Créer un tableau d'objet de la classe char
  ClasseChar ob[10] = { 'a', 'b', 'c','d', 'e', 'f',
                     'g', 'h', 'i', 'j' };

  for(int i = 0; i <10; i++)
    cout << ob[ i ].get_ch() << ' ';

  cout << endl;

  return 0;
}

Leave a Reply

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