Fehlermeldung bei Konsolenanwendung :|
-
Hallo,
ich schreibe grad ein programm wo es um lernen von OOP geht. ich habe die Klassen fix forgegeben bekommen mit attribute und Methoden. Stecke aber dennoch jetzt fest denke es liegt an grundsätzlichem verständsnis!
ich habe eine klasse SVGDocument diese soll nur eine doppeltverkettete liste verwalten.
Sie ruft nur methoden einer anderen Klasse (SVGObjectList)auf. Ein aufruf sieht wie folgt ausvoid SVGObjectList::addNode(const std::string, SVGObject* object)
Also er kriegt ein string und ein Pointer von SVGObject übergeben soweit ist alles klar. Das problem ist jetzt aber das SVGObject eine Abstrakte Klasse ist die darf doch keine attribute haben oder irre ich mich?
Weiters hat diese Abstrakte klasse 5 unter Klassen svgcircle, svgtext und andere. im SVGDocument gibt es jetzt folgende Methode.19 bool SVGDocument::addCircle(const std::string& id, const SVGCoord& center, int radius,
20 const std::string& fill)diese Methode kriegt also alle parameter die man für ein erzeugen eines Kreises braucht übergeben. Und nun zu meinem Quellcode:
Als 1. die Methode wie ich sich gerne programmiert hätte!18 //------------------------------------------------------------------------------ 19 bool SVGDocument::addCircle(const std::string& id, const SVGCoord& center, int radius, 20 const std::string& fill) 21 { 22 SVGObject* blubb[0]; 23 blubb[0] = new SVGObject::SVGCircle(center, radius, fill); 24 25 if (blubb[0] != NULL) 26 { 27 object_.addNode(id, blubb[0]); 28 return true; 29 } 30 else 31 return false; 32 }
Ich poste hier mal die header als auch die cpp file der abstrakten Klasse sowie der circle unterklasse:
1 /* 2 * SVGCircle.cpp 3 * 4 * Created on: 25.03.2009 5 * Author: Martin Glanzer 6 */ 7 8 #include "svgcircle.h" 9 10 SVGCircle::SVGCircle(const SVGCoord& center, int radius, const std::string& fill) 11 : center_(center), radius_(radius), fill_(fill) 12 { 13 } 14 15 SVGCircle::~SVGCircle() 16 { 17 } 18 19 void SVGCircle::writeSVGTag(std::ostream& file) 20 { 21 //todo: write svg-tag to file 22 } 23 24 const char* SVGCircle::getShortName() 25 { 26 return "ci"; 27 } 28 29 1 /* 2 * SVGCircle.h 3 * 4 * Created on: 25.03.2009 5 * Author: Martin Glanzer 6 */ 7 8 #ifndef SVGCIRCLE_H_ 9 #define SVGCIRCLE_H_ 10 11 #include "svgobject.h" 12 #include "svgcoord.h" 13 #include <iostream> 14 15 class SVGCircle : public SVGObject { 16 private: 17 SVGCoord center_; 18 int radius_; 19 std::string fill_; 20 SVGCircle (const SVGCircle &); //copy constructor always private 21 public: 22 SVGCircle(const SVGCoord& center, int radius, const std::string& fill); 23 virtual ~SVGCircle(); 24 25 virtual void writeSVGTag(std::ostream& file); 26 virtual const char* getShortName(); 27 }; 28 29 #endif /* SVGCIRCLE_H_ */ ~ 1 // 2 // SVGObject.h 3 // 4 // Created on: 25.03.2009 5 // Author: Martin Glanzer 6 // 7 8 #ifndef SVGOBJECT_H_ 9 #define SVGOBJECT_H_ 10 11 #include <iostream> 12 13 class SVGObject { 14 15 public: 16 SVGObject() {}; 17 virtual ~SVGObject() {}; 18 19 virtual void writeSVGTag(std::ostream& file) = 0; 20 virtual const char* getShortName() = 0; 21 }; 22 23 #endif // SVGOBJECT_H_
Und jetzt bekomme ich folgende Fehlermeldung:
svgdocument.cpp: In member function âbool SVGDocument::addCircle(const std::string&, const SVGCoord&, const SVGCoord&)â:
svgdocument.cpp:22: error: expected type-specifier
svgdocument.cpp:22: error: cannot convert âintâ to âSVGObjectâ in initialization
svgdocument.cpp:22: error: expected â,â or â;âMeinen Freund google hab ich dazu schon gefragt :|
ich werde daraus einfach net schlau. Vlt. könnt ihr mir bischen weiterhelfen.lg
Christoph
-
Falsches Forum, das gehört ins C++ Forum.
Dein Beitrag wird sicher bald verschoben.Simon
-
Tschuldigung. Ja dachte ich wäre hier richtig
-
Ein Fehler ist sicher hier:
// new SVGObject::SVGCircle(center, radius, fill); // sollte wohl eher wie folgt heissen new SVGCircle(center, radius, fill);
Simon
-
auch diese version hatte ich schon bzw.
hatte ich auch schon
SVGCircle::SVGCircle
leider selber fehler :|