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
| #include <iostream>
#include <malloc.h>
using namespace std;
class Proj
{
public:
char **args;
int nb_args;
string nom;
Proj(){nb_args=1;
args=reinterpret_cast <char**>(malloc(sizeof(char*)*nb_args));
sprintf(args[0],"%s","essai");
nom="lambi";
}
Proj (Proj &prj);
Proj operator=(Proj &prj);
~Proj(){free(args);}
};
class Carte
{
public:
Proj lamb;
int a;
Carte(int aa, Proj prj){a=aa;lamb=prj;} // here is my problem : comment
//definir mon operateur = pour Proj ? je ne peux pas utiliser mon copie constructeur...
~Carte(){};
};
Proj::Proj(Proj &prj) // constructeur par copie (a priori inutilise)
{
nb_args=prj.nb_args;
args=reinterpret_cast<char**>(malloc(sizeof(char*)*nb_args));
for(int i=0; i<nb_args;i++)
args[i]=prj.args[i];
}
Proj Proj::operator=(Proj &prj)
{
nb_args=prj.nb_args;
// mais je ne peux pas faire de malloc ici quand même !!
// Alors comment copier prj.args dans args ? sachant qu'ils
// n'ont même pas forcément la même taille ?
}
main()
{
Proj exemple_proj;
Carte(4,exemple_proj);
} |
Partager