Anfänger, verstehe Ausgabe nicht ;(
-
Folgender Code:
#include <iostream> using std::cout; using std::endl; class Vektor3 { private: int x; int y; int z; public: Vektor3 (int, int, int); void print () { cout << endl; cout << "( " << x << " )" << endl; cout << "( " << y << " )" << endl; cout << "( " << z << " )" << endl; cout << endl; } }; Vektor3::Vektor3 (int xx, int yy, int zz) { xx = x; yy = y; zz = z; } int main () { Vektor3 v0 (3, 2, 1); v0.print (); return 0; }
Folgende Ausgabe:
ghjkls-macbook-air:T ghjkllkjhg$ cd "/Users/ghjkllkjhg/Documents/Code/" && g++ tempCodeRunnerFile.cpp -o tempCodeRunnerFile && "/Users/ghjkllkjhg/Documents/Code/"tempCodeRunnerFile ( -508721072 ) ( 32766 ) ( 268537910 ) ghjkls-macbook-air:Code ghjkllkjhg$
Ich erwarte die Ausgabe anders, nämlich die Werte 3, 2, 1.
Was geht hier schief?
Danke für eure Hilfe
-
@gudi sagte in Anfänger, verstehe Ausgabe nicht :
xx = x; yy = y; zz = z;
Falschrum, versuchs mal so:
x = xx; y = yy; z = zz;
-
Mit eriner Member-Initializer-List wäre das nicht passiert.