[ Acko95 @ 22.01.2012. 17:45 ] @
[code] //Preklapanje funkcija clanica klasa #include <iostream> using namespace std; typedef unsigned short int ushort; enum BOOL { FALSE, TRUE }; class Rectangle { public: // konstruktori Rectangle(ushort width, ushort height); ~Rectangle() {} // preklopljena klasna funkcija DrawShape void DrawShape() const; void DrawShape(ushort aWidth, ushort aHeight) const; private: ushort itsWidth; ushort itsHeight; }; // implementacija konstruktora Rectangle::Rectangle(ushort width, ushort height) { itsWidth = width; itsHeight = height; } // preklopljena DrawShape ne prihvata vrednosti // crta bazirajuci se na tekucim vrednostima clanova klase void Rectangle::DrawShape() { DrawShape( itsWidth, itsHeight ); } // preklopljena DrawShape prihvata dve vrednosti // crta oblik bazirajuci se na parametrima void Rectangle::DrawShape(ushort width, ushort height) { for ( ushort i = 0, i < height << i++ ) { for ( ushort j = 0, j < width << j++ ) { cout << "*"; } cout << endl; } } // Demonstrira program koji demonstrira preklopljene funkcije int main() { // inicijalizuje pravougaonik na 30,5 Rectangle theRect(30,5); cout << "DrawShape(); \n"; theRect.DrawShape(); cout << "\nDrawShape(40,2); \n"; theRect.DrawShape(40,2); cin.get(); return 0; } Radim u Microsoftovom Visual c++ 2010, i izbacuje mi gresku kod inicijalizacije DrawRect() funkcija, kaze: No instace of overload function "Rectange::DrawShape" matches the specified type, a dole pise: ' void Rectangle::DrawFunction(void) ' : overloaded member function not found in 'Rectangle' see declaration of 'Rectangle'. I isto to za drugu funkciju DrawShape, nzm u cemu je problem ako bi neko mogao da mi razjasni bio bih mu zahvalan :D |