Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
wenn ich das static wegpack kommt vom compiler: "Die erneute Deklaration der Memberfunktion ist unzulässig" sowie "Ungültiger Verweis auf nicht-statischen Member 'CSoldat::Anzahl_Schwertkaempfer' " und "'Typumwandlung': 'int CSoldat::* ' kann nicht in 'char *' konvertiert werden" das dann halt für jede variable im public der basisklasse. dann lieber doch mit static am anfangDas kann schon sein, dass der Faxen gemacht hat, je nachdem, wie Du es programmiert hast. Aber static sollte man wirklich vermeiden. Notfalls schau nochmal in ein Buch, wie Attribute von Klassen funktionieren.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
void speichern () { ofstream Output ("Save.sav", ios::binary); Output.write ((char*) &Gold, sizeof (Gold)); Output.write ((char*) &Rohstoff_Holz, sizeof (Rohstoff_Holz)); Output.write ((char*) &Rohstoff_Eisen, sizeof (Rohstoff_Eisen)); Output.write ((char*) &Bevoelkerung, sizeof (Bevoelkerung)); Output.write ((char*) &CSoldat::Anzahl_Bogenschuetze, sizeof (CSoldat::Anzahl_Bogenschuetze)); Output.write ((char*) &CSoldat::Anzahl_Katapult, sizeof (CSoldat::Anzahl_Katapult)); Output.write ((char*) &CSoldat::Anzahl_Reiter, sizeof (CSoldat::Anzahl_Reiter)); Output.write ((char*) &CSoldat::Anzahl_Schwertkaempfer, sizeof (CSoldat::Anzahl_Schwertkaempfer)); Output.close (); cout << "Gespeichert." << endl; }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
void laden () { ifstream Input ("Save.sav", ios::binary); Input.read ((char*) &Gold, sizeof (Gold)); Input.read ((char*) &Rohstoff_Holz, sizeof (Rohstoff_Holz)); Input.read ((char*) &Rohstoff_Eisen, sizeof (Rohstoff_Eisen)); Input.read ((char*) &Bevoelkerung, sizeof (Bevoelkerung)); Input.read ((char*) &CSoldat::Anzahl_Bogenschuetze, sizeof (CSoldat::Anzahl_Bogenschuetze)); Input.read ((char*) &CSoldat::Anzahl_Katapult, sizeof (CSoldat::Anzahl_Katapult)); Input.read ((char*) &CSoldat::Anzahl_Reiter, sizeof (CSoldat::Anzahl_Reiter)); Input.read ((char*) &CSoldat::Anzahl_Schwertkaempfer, sizeof (CSoldat::Anzahl_Schwertkaempfer)); Input.close (); cout << "Geladen." << endl; } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
void someClass::save ( const CSoldier& soldier ) { ofstream output ("Save.sav", ios::binary); unsigned int fileVersion = 0; output << fileVersion; output << gold; output << wood; output << iron; output << population; output << soldier.getArcherCount(); output << soldier.getCatapultCount(); output << soldier.getRiderCount(); output << soldier.getSwordCount(); output.close (); cout << "Gespeichert." << endl; }; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
void someClass::save ( const CSoldier& soldier ) { ofstream output ("Save.sav", ios::binary); unsigned int fileVersion = 0; output << fileVersion; output << gold; output << wood; output << iron; output << population; output << soldier; // wahlweise: // soldier.save ( output ); cout << "Gespeichert." << endl; }; |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Werbeanzeige