invalid in-class initialization of static data member of non-integral type

hi everybody
i m new with C++ and i have some issues i have 4 classes: date, personne, employe(derived from personne) and Cie.
in cie i have to use the private members : a pointers array of 25 employes
and i get this errors

5 C:\cours cpp\tps\tp3\debut_tp3_etudiants\testEmploye.cpp In file included from ../tps/tp3/debut_tp3_etudiants/testEmploye.cpp 
10 C:\cours cpp\tps\tp3\debut_tp3_etudiants\classCie.h `new' cannot appear in a constant-expression 
10 C:\cours cpp\tps\tp3\debut_tp3_etudiants\classCie.h ISO C++ forbids initialization of member `tabEmp' 
10 C:\cours cpp\tps\tp3\debut_tp3_etudiants\classCie.h making `tabEmp' static 
10 C:\cours cpp\tps\tp3\debut_tp3_etudiants\classCie.h invalid in-class initialization of static data member of non-integral type `Employe



this is my classCie.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef _classCie_H
#define _classCie_H
#include"classEmploye.h"
#include<iostream>
#include<string>

using namespace std;

class Cie{
	Employe *tabEmp = new Employe[25];
	int nbEmp; //nombre effectif des employes 
	string nomCie;
	
    public:
		Cie();
        Cie(string);
		void ajoutEmploye(string, string);
		Employe * chercherEmploye(string, string, char);
		float sommeSalaire();
		Employe * plusVieux();
		void affiche();
};
#endif 


and this is my classCie.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "classEmploye.h"
#include "classCie.h"
#include "classDate.h"
#include "classPersonne.h"
#include<string>

//Cie::Cie()::Employe(" ", " "){

//}


Cie::Cie(string nom){
	nbEmp = 0;
	nomCie= nom;
}

void Cie::ajoutEmploye(string detailPer, string detailEmp){
	*tabEmp = new Employe(detailPer, detailEmp);
	nbEmp++;
	tabEmp++;

}

Employe * Cie::chercherEmploye(string nom, string prenom, char sexe){

	Employe **ptr;
	for (ptr=tabEmp;ptr<tabEmp+nbEmp;ptr++){
		if (**ptr->cEstLui(nom, prenom, sexe) return **ptr;
		else return NULL:
	}

}

float Cie::sommeSalaire(){
    Employe **ptr;
    float somme = 0;
	for(ptr=tabEmp;ptr<tabEmp+nbEmp;ptr++)
		somme=somme+(**ptr->getSalaire());
	return somme;
}

Employe * Cie::plusVieux(){
	Employe *ptrMax;  //pour sauvegarder l'adresse del 'employe le plus age
	Employe **ptr;
    Date d1(1,1,1000);
	for(ptr=tabEmp;ptr<tabEmp+nbEmp;ptr++)
		if ((**ptr->getNaiss().plusGrande(d1) == false)) {
		
			ptrMax = *ptr;
			d1= *(*ptr->getNaiss());
		}

	return ptrMax;
}

void Cie::affiche(){
	Employe **ptr;
    if (nbEmp==0) cout<<"Oups...il n'y a pas d'employe dans la cie...\n";
	else{
		
		cout<<"la liste des employes est la suivante:\n";
		for(ptr=tabEmp; ptr<tabEmp+nbEmp; ptr++) 
       *(*ptr)->affiche()::Employe;
    }
   
}


please i need your help thank you



The error you are getting is because you are calling the new operator in an illegal place. In your constructor initialize tapEmploye there.
Topic archived. No new replies allowed.