Hey all,
I am just getting into writing code in C++ and have written code in JAVA and FORTRAN a while back - so I am a little rusty.
I am just trying to write a simple Class to get the feel for it all. Basically the class CRectangle has the input of width and length, the area() member returns the area. I have included a number of get functions too, just for practise.
When I run this without seperating the code into a header file, a function file (?) - where you define the construct and member functions - and a main program, the program works fine.
Now that I have seperated it, it is not working, with the errors:
In file included from CRectangle.cpp:2:
CRectangle.h:9: error: expected unqualified-id before ‘int’
CRectangle.h:9: error: expected ‘)’ before ‘int’
CRectangle.h:7: error: an anonymous struct cannot have function members
CRectangle.h:16: error: abstract declarator ‘<anonymous class>’ used as declaration
CRectangle.cpp:5: error: expected identifier before ‘(’ token
CRectangle.cpp:5: error: expected ‘;’ before ‘(’ token
CRectangle.cpp:5: error: expected unqualified-id before ‘int’
CRectangle.cpp:5: error: expected ‘)’ before ‘int’
CRectangle.cpp:10: error: explicit qualification in declaration of ‘int area()’
CRectangle.cpp: In function ‘int area()’:
CRectangle.cpp:11: error: ‘length’ was not declared in this scope
CRectangle.cpp:11: error: ‘width’ was not declared in this scope
CRectangle.cpp: At global scope:
CRectangle.cpp:14: error: explicit qualification in declaration of ‘int getlength()’
CRectangle.cpp: In function ‘int getlength()’:
CRectangle.cpp:15: error: ‘length’ was not declared in this scope
CRectangle.cpp: At global scope:
CRectangle.cpp:18: error: explicit qualification in declaration of ‘int getwidth()’
CRectangle.cpp: In function ‘int getwidth()’:
CRectangle.cpp:19: error: ‘width’ was not declared in this scope
In file included from mainrecttest.cpp:2:
CRectangle.h:9: error: expected unqualified-id before ‘int’
CRectangle.h:9: error: expected ‘)’ before ‘int’
CRectangle.h:7: error: an anonymous struct cannot have function members
CRectangle.h:16: error: abstract declarator ‘<anonymous class>’ used as declaration
mainrecttest.cpp: In function ‘int main()’:
mainrecttest.cpp:34: error: ‘rect’ was not declared in this scope
I know there is a simple mistake somewhere in the syntax, but for the life of me, I cannot find it. Please help!


LinkBack URL
About LinkBacks




Reply With Quote



Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum