.
viande schrieb:
@filmor Du hast die Referenz für das print vergessen
Jau.
Simon2 schrieb:
Egal - wir sind uns einig
Jau.
PACoSys schrieb:
Ich blick's irgendwie nicht mehr ganz. Kann mal bitte jemand das Beispiel berichtigen bzw. vervollständigen?
Entweder so wie CStoll sagte, oder du gehst den C++-igen Weg.
Ich gehe jetzt einfach mal davon aus, dass Point so primitiv bleiben soll, dann erübrigt sich nämlich die Diskussion um virtuelle Funktionen:
#ifndef POINT_H
#define POINT_H
#include <iosfwd>
class Point
{
public:
Point(double x, double y, double z) : x(x), y(y), z(z) { }
double GetX() const { return x; }
double GetY() const { return y; }
double GetZ() const { return z; }
inline friend std::ostream& operator<< (std::ostream& os, Point const& p);
{
os << "Node " << p.index << "\n----------\nx: " << p.x << " y: " << p.y << " z: " << p.z;
return os;
}
bool operator == (const Point & crP2) const { return ((x == crP2.GetX()) && (y == crP2.GetY()) && (z == crP2.GetZ())); }
private:
double x;
double y;
double z;
};
#endif
Jetzt kannst du beliebige Point Objekte in beliebige Streams stopfen. Du kannst also folgendes alles tun:
Point e3 (0.0, 0.0, 1.0);
std::cout << e3;
ostringstream ost;
ost << e3;
std::string s = ost.str();
ofstream file ("bla");
file << e3;
Na, is das was?