Опытный
 
Профиль
Группа: Участник
Сообщений: 740
Регистрация: 12.1.2008
Где: Germany
Репутация: 1 Всего: 1
|
Нонсенс, не знаю что делать. Не могу высчитать s.lenght() s - типа стринг. Ругается, что не знает такого метода, хотя видит что эта переменная стринг. Короче, лажа какая то.. :( Уже не знаю в какую сторону смотреть. .:(:(:( Если писать стринг в мейн, тогда видит, в cpp и h файликах не видит. Вот исходники. Вопрос в том, почему s понимается как string, а методов своих не видит????... :(Смотреть cpp строка 117. Благодарю. main | Код |
// -------------------------------------------------------------- #include <iostream> #include <math.h> using namespace std;
#include "RGB_Pixel.h" // Darstellung von Pixeln #include "Image.h" // Zweidimensionales Bild #include "BmpWrite.h" // Schreiben von BMP-Dateien #include "GrafikElement.h" // Grafik-Objekte
int main() { //try { // Vereinbarung einiger Farben RGB_Pixel red(255,0,0); RGB_Pixel green(0,255,0); RGB_Pixel blue(0,0,255); RGB_Pixel yellow(255,255,0); RGB_Pixel black;
// Bild I vereinbaren const int height=200, width=150, iterations=100; Image I(width,height);
//Punkt().draw(I); //Linie().draw(I); //Rechteck(30,30,120,60,green).draw(I); //RechteckGefuellt(30,150,110,120,blue,green).draw(I); Zeichen(100,100,'K',yellow,green).draw(I); Textzeile(50,50,"BLASSS",red,blue).draw(I);
// // Klassenhierarchie anwenden und ueberpruefen // // Einfache Objekte // RechteckGefuellt(3,20, width-3, 25, green,blue).draw(I); // Textzeile(38,11,"Testbild",red,black).draw(I); // Rechteck(0,0,width-1,height-1,green).draw(I); // // Objekte mittels GrafikElement-Referenz ansprechen // Rechteck r1(8,height/2-2,130,height/2+15,yellow); // Rechteck r2; // GrafikElement &g1=r1; // Rechteck r1 mittels GrafikElement-Referenz ansprechen // GrafikElement &g2=r2; // Rechteck r2 mittels GrafikElement-Referenz ansprechen // g2=g1; // r2=r1; // g2.add_offset(15,30); // r2 verschieben // g1.draw(I); // r1 zeichnen // g2.draw(I); // r2 zeichnen // // Objekte clonen und mittels GrafikElement-Zeiger ansprechen // GrafikElement* pg(g2.clone()); // Clone-Objekt erstellen // pg->add_offset(15,30); // Bezugspunkt im Clone-Objekt verschieben // pg->draw(I); // Clone-Objekt zeichnen // delete pg; // Clone-Objekt freigeben // // Fehlerfall ueberpruefen // try { // Linie l; // l=g1; // } catch(...) { // cout << "Rechteck an Linie zuweisen ist nicht erlaubt" << endl; // } // // Objekte mittels GrafikElement-Zeiger ansprechen // for (int k=0; k<iterations; k++) { // int i=int(100.0*sin(3.0*k*2.0*M_PI/iterations))+height/2; // GrafikElement* pl = new Linie(2*i/3,4*i/3,width-i,height-3*i,green); // pl->draw(I); // GrafikElement* pk = new Linie(0,0,0,0,black); // *pk=*pl; // pk->add_offset(40,30); // pk->draw(I); // delete pl; // delete pk; // } // Textzeile(10,height/2,"OOP ist sch\x94n!",yellow,black).draw(I); // // // Bild schreiben BmpWrite("P6.bmp",I); // } catch(...) { cout << "Ausnahme gefangen" << endl; } }
|
cpp | Код | #include "GrafikElement.h" using namespace::std;
//-------------***Punkt::draw***--------------------------------------------
void Punkt::draw(Image& I) { I[xs][ys] = c; }
//-------------***Linie::draw***--------------------------------------------
void Linie::draw(Image& I) {
int xP = xs; int yP = ys; int xQ = xe; int yQ = ye;
int x = xP; int y = yP; int D = 0; int HX = xQ - xP; int HY = yQ - yP; int xInc = 1; int yInc = 1;
if (HX < 0) { xInc = -1; HX = -HX; } if (HY < 0) { yInc = -1; HY = -HY; }
if (HY <= HX) { // main direction is x const int c = 2 * HX; const int M = 2 * HY; while (true) { I[y][x] = Linie::c; if (x == xQ) { break; } x += xInc; D += M; if (D > HX) { y += yInc; D -= c; } } } else { // main direction is y const int c = 2 * HY; const int M = 2 * HX; while (true) { I[y][x] = Linie::c; if (y == yQ) { break; } y += yInc; D += M; if (D > HY) { x += xInc; D -= c; } } } }
//-------------***Rechteck::draw***--------------------------------------------
void Rechteck::draw(Image& I){
Linie(xs,ys,xe-(xe-xs),ye,c).draw(I); Linie(xe-(xe-xs),ye,xe,ye,c).draw(I); Linie(xe,ye,xs-(xs-xe),ys,c).draw(I); Linie(xs-(xs-xe),ys,xs,ys,c).draw(I);
}
//-------------***Rechteck::draw***--------------------------------------------
void RechteckGefuellt::draw(Image& I) {
Rechteck(xs, ys, xe, ye, c).draw(I); if (ys < ye) { for (int i = ys + 1; i < ye; ++i) Linie(xs - (xs - xe), i, xs, i, c).draw(I); } else { for (int i = ye + 1; i < ys; ++i) Linie(xs - (xs - xe), i, xs, i, c).draw(I); } }
//-------------***Zeichen::draw***--------------------------------------------
void Zeichen::draw(Image& I){
SimpleFont *ptr = new SimpleFont(ch);
for (int i=0;i<ptr->height();++i){ for(int j=0;j<ptr->width();++j){
if((*ptr)[i][j]) I[xs+i][ys+j]=fg; else I[xs+i][ys+j]=bg; } } }
//-------------***Textzeile::draw***--------------------------------------------
void Textzeile::draw(Image& I){
for(int i=0;i<s.lenght();++i) int j=0; }
//----------------------------------------------------------------------------
|
h | Код |
#include <iostream> #include <iomanip> #include <string> using namespace::std; #include "RGB_Pixel.h" #include "Image.h" #include "SimpleFont.h"
class GrafikElement { protected: int xs; int ys;
public:
GrafikElement() : xs(10), ys(20) {}; GrafikElement(int _x, int _y) : xs(_x), ys(_y) {}; virtual ~GrafikElement() {};
virtual void draw(Image&) = 0; GrafikElement & operator=(const GrafikElement& r); void add_offset(int, int); GrafikElement* clone();
};
class Punkt : protected GrafikElement { private: RGB_Pixel c; public:
Punkt(int _xBasis, int _yBasis, RGB_Pixel color) : GrafikElement(_xBasis, _yBasis), c(color) {}; Punkt() : c(RGB_Pixel(255, 0, 0)) {}; ~Punkt() {};
void draw(Image&);
};
class Linie : protected GrafikElement { private: int xe; int ye; RGB_Pixel c; public:
Linie(int _xBasis, int _yBasis, int _x, int _y, RGB_Pixel color) : GrafikElement(_xBasis, _yBasis), xe(_x), ye(_y), c(color) {}; Linie() : xe(37), ye(39), c(RGB_Pixel(255, 0, 0)), GrafikElement(10, 20) {}; ~Linie(){};
void draw(Image&);
};
class Rechteck : protected GrafikElement { protected: int xe; int ye; RGB_Pixel c; public:
Rechteck(int _xBasis, int _yBasis, int _x, int _y, RGB_Pixel color) : GrafikElement(_xBasis, _yBasis), xe(_x), ye(_y), c(color) {}; Rechteck() : xe(37), ye(39), c(RGB_Pixel(255, 0, 0)), GrafikElement(10, 20) {}; ~Rechteck(){};
void draw(Image&);
};
class Zeichen : protected GrafikElement { private: unsigned char ch; RGB_Pixel fg; RGB_Pixel bg; public:
Zeichen(int _xBasis, int _yBasis, unsigned char cha, RGB_Pixel fColor, RGB_Pixel bColor) : GrafikElement(_xBasis, _yBasis), ch(cha), fg(fColor), bg(bColor) {}; Zeichen() : ch('\x94'), fg(RGB_Pixel(0, 0, 255)), bg(RGB_Pixel(0, 0, 0)) {}; ~Zeichen(){};
void draw(Image&);
};
class Textzeile : protected GrafikElement { private: string s; RGB_Pixel fg; RGB_Pixel bg; public: string temp; Textzeile(int _xBasis, int _yBasis, string str, RGB_Pixel fColor, RGB_Pixel bColor) : GrafikElement(_xBasis, _yBasis), s(str), fg(fColor), bg(bColor) {}; Textzeile() : s("Hello World"), fg(RGB_Pixel(0, 0, 255)), bg(RGB_Pixel(0, 0, 0)) {}; ~Textzeile(){};
void draw(Image&);
};
class RechteckGefuellt : protected Rechteck { private: RGB_Pixel f; public:
RechteckGefuellt(int _xBasis, int _yBasis, int _xRechteck, int _yRechteck, RGB_Pixel cColor, RGB_Pixel fColor) : Rechteck(_xBasis, _yBasis, _xRechteck, _yRechteck, cColor), f(fColor) {}; RechteckGefuellt() : f(RGB_Pixel(0, 255, 0)) {}; ~RechteckGefuellt(){}; void draw(Image&);
};
|
ОШИБКА! | Код | "/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf make[1]: Entering directory `/d/NetBeans/C++_Projects/Praktikum6' "/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/praktikum6.exe make[2]: Entering directory `/d/NetBeans/C++_Projects/Praktikum6' mkdir -p build/Debug/MinGW-Windows/_ext/1255726339 rm -f build/Debug/MinGW-Windows/_ext/1255726339/GrafikElement.o.d g++.exe -c -g -MMD -MP -MF build/Debug/MinGW-Windows/_ext/1255726339/GrafikElement.o.d -o build/Debug/MinGW-Windows/_ext/1255726339/GrafikElement.o /D/NetBeans/C++_Projects/Praktikum6/GrafikElement.cpp d:/NetBeans/C++_Projects/Praktikum6/GrafikElement.cpp: In member function `virtual void Textzeile::draw(Image&)': d:/NetBeans/C++_Projects/Praktikum6/GrafikElement.cpp:117: error: 'struct std::string' has no member named 'lenght' make[2]: *** [build/Debug/MinGW-Windows/_ext/1255726339/GrafikElement.o] Error 1 make[1]: *** [.build-conf] Error 2 make[2]: Leaving directory `/d/NetBeans/C++_Projects/Praktikum6' make[1]: Leaving directory `/d/NetBeans/C++_Projects/Praktikum6' make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 3s)
|
Это сообщение отредактировал(а) Killer_13 - 25.11.2010, 22:54
|