000
17.04.2014, 03:55 Uhr
Yadgar
|
Hi(gh)!
Zwei Klassen für POV-Ray-Objekte, eine für Koordinatentripel:
C++: |
class POV_point { private: string name; float xval; float yval; float zval; public: POV_point (float, float, float); POV_point (string, float, float, float); void set (float, float, float); void dump (void); };
POV_point::POV_point (float x, float y, float z) { xval = x; yval = y; zval = z; }
POV_point::POV_point(string n, float x, float y, float z) { name = n; xval = x; yval = y; zval = z; }
void POV_point::set (float x, float y, float z) { xval = x; yval = y; zval = z; }
void POV_point::dump (void) { if (name.compare("")) cout << name << ":" << endl; cout << "<" << xval << ", " << yval << ", " << zval << ">" << endl; cout << endl; }
|
eine für Quader ("box"):
C++: |
class POV_box { private: const string type = "box"; string name; POV_point corner1; POV_point corner2; public: POV_box (string, float, float, float, float, float, float); void set (float, float, float, float, float, float); void dump (void); };
POV_box::POV_box (string n, float x1, float y1, float z1, float x2, float y2, float z2) { name = n; POV_point corner1 (x1, y1, z1); POV_point corner2 (x2, y2, z2); }
void POV_box::set (float x1, float y1, float z1, float x2, float y2, float z2) { corner1.set (x1, y1, z1); corner2.set (x2, y2, z2); }
void POV_box::dump (void) { cout << type << "\n" << "{" << "\n" << " " << endl; corner1.dump(); cout << ", " << endl; corner2.dump(); cout << "\n" << "}" << "\n" << endl; }
|
Der Compiler erkennt anscheinend nicht, dass der Aufruf des Konstruktors von POV_point innerhalb des Konstruktors von POV_box durchaus dem Prototypen in POV_point (der Konstruktor ist überladen, ich verwende hier die Version ohne Namensstring) entspricht, ich bekomme eine Riesenlatte an Fehlermeldungen:
Code: |
yadgar@debian:/media/Raytracing/Povscn/Flags/Coats of Arms$ g++ -std=c++11 flagmaker.cc -o flagmaker flagmaker.cc: In constructor ‘POV_box::POV_box(std::string, float, float, float, float, float, float)’: flagmaker.cc:63:87: error: no matching function for call to ‘POV_point::POV_point()’ flagmaker.cc:63:87: note: candidates are: flagmaker.cc:28:1: note: POV_point::POV_point(std::string, float, float, float) flagmaker.cc:28:1: note: candidate expects 4 arguments, 0 provided flagmaker.cc:21:1: note: POV_point::POV_point(float, float, float) flagmaker.cc:21:1: note: candidate expects 3 arguments, 0 provided flagmaker.cc:7:7: note: POV_point::POV_point(const POV_point&) flagmaker.cc:7:7: note: candidate expects 1 argument, 0 provided flagmaker.cc:7:7: note: POV_point::POV_point(POV_point&&) flagmaker.cc:7:7: note: candidate expects 1 argument, 0 provided flagmaker.cc:63:87: error: no matching function for call to ‘POV_point::POV_point()’ flagmaker.cc:63:87: note: candidates are: flagmaker.cc:28:1: note: POV_point::POV_point(std::string, float, float, float) flagmaker.cc:28:1: note: candidate expects 4 arguments, 0 provided flagmaker.cc:21:1: note: POV_point::POV_point(float, float, float) flagmaker.cc:21:1: note: candidate expects 3 arguments, 0 provided flagmaker.cc:7:7: note: POV_point::POV_point(const POV_point&) flagmaker.cc:7:7: note: candidate expects 1 argument, 0 provided flagmaker.cc:7:7: note: POV_point::POV_point(POV_point&&) flagmaker.cc:7:7: note: candidate expects 1 argument, 0 provided
|
und kann mir beim besten Willen keinen Reim darauf machen!
Vor einigen Tagen wurde eine ähnliche Konstruktion, ebenfalls mit geschachtelten Konstruktoren:
C++: |
class SVG_color { private: short red; short green; short blue; string name; public: SVG_color (short, short, short); // Konstruktor, ohne Namensstring SVG_color (string, short, short, short); // Konstruktor, mit Namensstring void set (short, short, short); // Zuweisung void dump (void); // Anzeige der Element-Werte };
SVG_color::SVG_color(short r=0, short g=0, short b=0) { red = r; green = g; blue = b; }
SVG_color::SVG_color(string n, short r=0, short g=0, short b=0) { name = n; red = r; green = g; blue = b; }
void SVG_color::set(short r=0, short g=0, short b=0) { red = r; green = g; blue = b; }
void SVG_color::dump(void) { if (name.compare("")) cout << name << ":" << endl; cout << "Red: " << red << ", " << "Green: " << green << ", " << "Blue: " << blue << endl; cout << endl; }
class SVG_rectangle { private: unsigned int startx; unsigned int starty; unsigned int width; unsigned int height; string name; SVG_color fill; public: SVG_rectangle (string, unsigned int, unsigned int, unsigned int, unsigned int, short, short, short); // Konstruktor void set (unsigned int, unsigned int, unsigned int, unsigned int, short, short, short); // Zuweisung void dump (void); // Anzeige der Element-Werte };
SVG_rectangle::SVG_rectangle(string n, unsigned int w, unsigned int h, unsigned int x=0, unsigned int y=0, short r=0, short g=0, short b=0) { name = n; startx = x; starty = y; width = w; height = h; SVG_color fill(r, g, b); }
void SVG_rectangle::set(unsigned int w, unsigned int h, unsigned int x=0, unsigned int y=0, short r=0, short g=0, short b=0) { startx = x; starty = y; width = w; height = h; fill.set(r, g, b); }
void SVG_rectangle::dump(void) { cout << name << ":" << endl; cout << "Upper left corner: x=" << startx << ", y=" << starty << endl; cout << "Width: " << width << endl; cout << "Height: " << height << endl; cout << "Fill:" << endl; fill.dump(); }
|
problemlos kompiliert! Wo soll da der Unterschied sein? Ich sehe keinen...
Bis bald im Khyberspace!
Yadgar -- Flagmaker - ein Programmier-Blog |