Problème d'initialisation

cs_briscard Messages postés 10 Date d'inscription mardi 16 décembre 2003 Statut Membre Dernière intervention 9 mars 2004 - 6 janv. 2004 à 11:25
cs_briscard Messages postés 10 Date d'inscription mardi 16 décembre 2003 Statut Membre Dernière intervention 9 mars 2004 - 6 janv. 2004 à 14:08
Bonjour à tous,

j'ai un problème avec l'initialisation d'un charactère an C++ sous DEV C++:
lorsque je fais:
unsigned char *RECALL_SWEEPTRACE = new unsigned char[1];
dans mon .h, et que je veut y mettre une valeur en hexa dans mon .c : RECALL_SWEEPTRACE=0x11;
il me ressort une erreur comme quoi il le prend pour un int.

Deuxième problème dans la classe principal de mon .c, j'ai comme paramètre une struct dans lequel je declare une multitude de pointeur sur tableau de char:

class Echange
{
public:
int RecupTrace(int nbTrace);
struct sweepTrace{
int nb;
char * NumberBytes;
NumberBytes = new char[1];
string SoftwareVersion;
char MeasureMode;
char *DateUniv = new char[3];
char *Date = new char[9];
char *Time = new char[7];
char *ReferenceNumber = new char[17];
char *DataPoints = new char[1];
char *StartFrequency = new char[3];
char *StopFrequency = new char[3];
char *MinimumFreqStepSize = new char[3];
char *ScaleTop = new char[3];
char *ScaleBottom = new char[3];
char *FreqMarker_1 = new char[1];
char *FreqMarker_2 = new char[1];
char *FreqMarker_3 = new char[1];
char *FreqMarker_4 = new char[1];
char *FreqMarker_5 = new char[1];
char *FreqMarker_6 = new char[1];
char Segment_1;
char StatusSegment_1;
char *StartX_1 = new char[3];
char *StartY_1 = new char[1];
char *EndX_1 = new char[3];
char *EndY_1 = new char[1];
char Segment_2;
char StatusSegment_2;
char *StartX_2 = new char[3];
char *StartY_2 = new char[1];
char *EndX_2 = new char[3];
char *EndY_2 = new char[1];
char Segment_3;
char StatusSegment_3;
char *StartX_3 = new char[3];
char *StartY_3 = new char[1];
char *EndX_3 = new char[3];
char *EndY_3 = new char[1];
char Segment_4;
char StatusSegment_4;
char *StartX_4 = new char[3];
char *StartY_4 = new char[1];
char *EndX_4 = new char[3];
char *EndY_4 = new char[1];
char Segment_5;
char StatusSegment_5;
char *StartX_5 = new char[3];
char *StartY_5 = new char[1];
char *EndX_5 = new char[3];
char *EndY_5 = new char[1];
char *StartDistance = new char[3];
char *StopDistance = new char[3];
char *DistMarker_1 = new char[1];
char *DistMarker_2 = new char[1];
char *DistMarker_3 = new char[1];
char *DistMarker_4 = new char[1];
char *DistMarker_5 = new char[1];
char *DistMarker_6 = new char[1];
char *RelativePropVelo = new char[3];
char *CableLoss = new char[3];
char StatusByte_1;
char StatusByte_2;
char StatusByte_3;
char StatusByte_4;
sweepTrace *Prec;
sweepTrace *Suiv;
};

il me sort une erreur a chaque fois que je fais new char
je comprend vraiment pas car j'ai suivant mon cours et logiquement c'est bon alors si quelqu'un peut m'aider...
Briscard

2 réponses

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
6 janv. 2004 à 12:25
les new doivent être mis dans le constructeur de la classe, les delete dans le destructeur. (c'est en java qu'on peut faire ça).

si tu connais la taille du tableau, inutile de fire un new (surtout pour des petites valeurs), déclare directemnt un tableau :

char ReferenceNumber[17];

unsigned char *RECALL_SWEEPTRACE = new unsigned char[1];

pour affecter une valeur :
*RECALL_SWEEPTRACE = 0x11;
0
cs_briscard Messages postés 10 Date d'inscription mardi 16 décembre 2003 Statut Membre Dernière intervention 9 mars 2004
6 janv. 2004 à 14:08
nikel!
ca marche impec, j'ai plus ka faire ma dll.
merci bcp
Briscard
0
Rejoignez-nous