W
CStoll schrieb:
Das sieht zumindest ganz danach aus, daß du deinen operator= vermurkst hast
In der Tat, es fehlte mir der Adress-Operator "&" Vielen Dank
#include <stdio.h>
#include <stdlib.h>
class count
{
private:
double dValue;
public:
bool showCount(char *comment=NULL) { fprintf(stderr,"Zahl (%s):: %lg\n",comment,dValue); return true; }
bool setCount(double val) { dValue=val; return true; }
double getValue() { return dValue; }
count() { dValue=0.; this->showCount("Create"); }
count(double val) { this->setCount(val); this->showCount("Init"); }
count(class count &zahl) { dValue=zahl.getValue(); this->showCount("Copy"); }
class count &operator=(class count &zahl)
{
if (this==&zahl) return *this;
this->setCount(zahl.getValue());
this->showCount("Assign");
return *this;
}
class count &operator+(class count &zahl)
{
fprintf(stderr,"+Operator::%lg + %lg =",this->getValue(),zahl.getValue());
this->setCount(dValue+zahl.getValue());
fprintf(stderr," %lg\n",this->getValue());
return *this;
}
class count &operator-(class count &zahl)
{
fprintf(stderr,"-Operator::%lg - %lg =",this->getValue(),zahl.getValue());
this->setCount(dValue-zahl.getValue());
fprintf(stderr," %lg\n",this->getValue());
return *this;
}
class count &operator*(class count &zahl)
{
fprintf(stderr,"*Operator::%lg * %lg =",this->getValue(),zahl.getValue());
this->setCount(dValue*zahl.getValue());
fprintf(stderr," %lg\n",this->getValue());
return *this;
}
~count() { dValue=0.; }
};
int main ()
{
class count x(1);
class count y(3);
class count z(5);
class count ergebnis;
ergebnis=(x+y+z)*z-y;
ergebnis.showCount("hat's den wert noch ?");
return 0;
}