I have a main class of an object called CEmploye and a child of this class called CTechnicien. This is the code for CEmploye
#pragma once
#include <iostream>
#include <string>
class CEmploye
{
public:
/*Constructeurs/Destructeurs*/
CEmploye ();
CEmploye (std::string p_nom, std::string p_prenom, int p_age, int p_anciennete);
~CEmploye ();
protected:
/*Nom de l'employe*/
std::string m_nom;
/*Prenom de l'employe*/
std::string m_prenom;
/*Age de l'employe*/
int m_age;
/*Annee d'anciennete de l'employe*/
int m_anciennete;
};
And this is the code for CTechnicien :
#pragma once
#include "CEmploye.h"
class CTechnicien :
public CEmploye
{
public:
/*Constructeur/Destructeur*/
CTechnicien ();
CTechnicien (int p_nbUniteProduite, std::string p_nom, std::string p_prenom, int p_age, int p_anciennete);
~CTechnicien ();
protected:
/*Nombre d'unite produite par le technicien*/
int m_nbUniteProduite;
static float BASE;
static float PART;
static float
I created an other class to manage everything and within it a vector of CEmploye :
std::vector<CEmploye> m_vecteurEmploye;
What I'm trying to do is to store a CTechnicien in this vector. But when I do, it seems like my CTechnicien is converted into a CEmploye and that's not what I want. So I have a method in my CPersonnel like that :
void CPersonnel::Embaucher (CEmploye * p_pNew)
{
m_vecteurEmploye.push_back (*p_pNew);
return;
}
And this is the bit of code that I did to store my class :
CPersonnel mainListe;
CTechnicien test (500, "test", "Test", 25, 0);
mainListe.Embaucher (&test);
So is there a way to store my CTechnicien in my vector of CEmploye whithout losing the fact that it's a CTechnicien ?