Bin nun bei Klassen.
Nun habe ich das Beispiel erweitert und auch ein wenig verändert.
Doch der Compiler spuckt folgende Fehlermeldungen aus:
|
Quellcode
|
1
2
|
1>c:\users\dennis\documents\visual studio 2008\projects\oop\oop\oop.cpp(20) : warning C4244: 'Argument': Konvertierung von 'double' in 'int', möglicher Datenverlust
1>c:\users\dennis\documents\visual studio 2008\projects\oop\oop\oop.cpp(22) : warning C4244: 'Argument': Konvertierung von 'double' in 'int', möglicher Datenverlust
|
Aber warum kann der das net in int konvertieren, das muss der doch garnet, weil ich doch die Variablen am Anfang als int deklariert habe. Warum denkt der auf einmal das wäre double?
Mein Program:
Reiter.cpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
|
#include "OPP.hpp"
#include <iostream>
using namespace std;
void CReiter::ZeigeDaten (int mGeschwindigkeit,
int mforce, int mGesundheit, int mMoral);
{
cout <<"Geschwindigkeit: " <<mGeschwindigkeit<<endl;
cout <<"Kraft : " <<mforce<<endl;
cout <<"Gesundheit : " <<mGesundheit<<endl;
cout <<"Moral : " <<mMoral<<endl;
}
|
OPP.hpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
class CReiter
{
private:
int mGeschwindigkeit;
int mforce;
int mGesundheit;
float mMoral;
public:
void ZeigeDaten (int mGeschwindigkeit,
int mforce, int mGesundheit, int mMoral);
};
|
OOP.cpp
|
C-/C++-Quelltext
|
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
|
#include <iostream>
#include "OPP.hpp"
using namespace std;
int main ()
{
CReiter Reiter1;
CReiter Reiter2;
/*Reiter1.mGeschwindigkeit = 100;
Reiter1.mforce = 25;
Reiter1.mGesundheit = 100;
Reiter1.mMoral =25.5;
Reiter2.mGeschwindigkeit = 200;
Reiter2.mforce = 10;
Reiter2.mGesundheit = 85;
Reiter2.mMoral =20.5;
*/
Reiter1.ZeigeDaten (100, 25, 100, 25.5);
cout<<endl;
Reiter2.ZeigeDaten(200, 10, 100, 25.5);
cin.get();
return 0;
}
|
Gruß Pixma