hi,
ive just started doing inheritance...and im not sure what exactlty i should put in .h files and .cpp files... heres what im trying to do...currently im getting compile errors...
Shape.h
Square.hCode:class Shape { protected: int length, width; public: Shape (int l, int w) { length = l; width = w;} virtual int area (void) = 0; };
Square.cppCode:#include "Shape.h" class Square: public Shape { public: Square(int l, int w): Shape(l,w){} int area(void); };
note this doesnt compile...i get the following errors..Code:#include "Square.h" #include "Shape.h" int Square::area (void) { return length*width; }
In file included from Square.cpp:1:
Square.h:1: error: parse error before `{' token
Square.h:6: error: parse error before `}' token
Square.cpp:3: error: invalid use of undefined type `class Square'
Square.h:1: error: forward declaration of `class Square'
Square.cpp: In member function `int Square::area()':
Square.cpp:4: error: `length' undeclared (first use this function)
Square.cpp:4: error: (Each undeclared identifier is reported only once for each
function it appears in.)
Square.cpp:4: error: `width' undeclared (first use this function)



LinkBack URL
About LinkBacks


