in this code why does the first("invNummer") is always 0, when I initializate it dynamically? When I do it as a static(two) it works.
class Computer {
private:
int invNummer;
char* osName;
int state; // 0 – aus, 1 - an
public:
Computer(int INV, char* OS, int st);
void info(){
cout << invNummer << " " << osName << " " << state << endl;
}
};
Computer::Computer(int INV, char* OS, int st): invNummer(INV), osName(OS), state(st){};
int main(){
Computer *one;
one = new Computer(10,(char *)"Windows",1);
delete eins;
Computer two(9,(char *)"Linux",0);
one->info();
two.info();
return 0;
}
Output looks like this:
0 Windows 1
9 Linux 0
Aucun commentaire:
Enregistrer un commentaire