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
|
#include<stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <iostream.h>
class Car {
public:
char Matricule[15];
char CarType[15];
Car(char *aMatricule,char *aType);
Car();
};
Car::Car() {
memset(Matricule,15,0);
memset(CarType,15,0);
}
Car::Car(char *aMatricule,char *aType) {
memcpy(CarType,aType,15);
memcpy(Matricule,aMatricule,15);
}
int main() {
Car Voiture("235 XXL 24","Luxe");
Car *Voitures = new Car[1];
memcpy(Voitures[0].Matricule,"144 FGH 56",15);
memcpy(Voitures[0].CarType,"Coupe",15);
Voitures[1]= Voiture;
printf("%s\n",Voiture.CarType);
printf("offsetof : %d\n", offsetof(Car,CarType));
system("pause");
return 0;
} |
Partager