Also wenn ich mir zur Klasse Punkt noch den entsprechenden Konstruktor hinzudenke (+ includen von iostream,und int main),dann tut das Programm das was du denkst.Es wird 60,70 ausgegeben.
Und nochmal als komplettes Bsp + Referenz.
Code:
#include <iostream>
using namespace std;
class Punkt
{
public :
int x, y ;
Punkt(int a,int b) : x(a),y(b) {}
};
void foo(Punkt *EinPunkt)
{
EinPunkt->x += 10 ;
EinPunkt->y += 20 ;
}
void foo(Punkt &EinPunkt)
{
EinPunkt.x += 10;
EinPunkt.y += 20;
}
int main()
{
Punkt aPoint(50, 50) ;
foo(&aPoint) ;
cout << aPoint.x << ", " << aPoint.y << endl ;
foo(aPoint);
cout << aPoint.x << ", " << aPoint.y << endl ;
}
Lesezeichen