From: the B. <th...@gm...> - 2002-09-29 08:39:43
|
Hello: I'm completely mystified as to why the file below won't compile. It's ridiculously simple, and compiles using VC6 and VC.NET: // POINT.H ///////////////////////////////////////////////// #ifndef POINT_H #define POINT_H struct Point { int id; // the point id double x; // x co-ordinate double y; // y co-ordinate }; void inputPoint( Point& pt ); void rotatePoint( double angle, Point& pt ); void outputPoint( const Point& pt ); #endif // RECT.H ////////////////////////////////////////////////// #ifndef RECT_H #define RECT_H #include "point.h" struct Rectangle { int id; // the rectangle ID Point bottom_left; Point top_left; Point top_right; Point bottom_right; }; void inputRectangle( Rectangle& rect ); void rotateRectangle( double angle, Rectangle& rect ); void outputRectangle( const Rectangle& rect ); #endif // RECT.CPP //////////////////////////////////////////////// // standard include files #include <iostream> #include <iomanip> // custom include files #include "rect.h" #include "point.h" using namespace std; // Function: inputRectangle void inputRectangle( Rectangle& rect ) { // Prompt user for values cout << "Enter the rectangle's ID: "; cin >> rect.id; cout << "Bottom left corner point:" << endl; inputPoint( rect.bottom_left ); return; } // Function: rotateRectangle void rotateRectangle( double angle, Rectangle& rect ) { rotatePoint( angle, rect.bottom_left ); rotatePoint( angle, rect.top_left ); rotatePoint( angle, rect.top_right ); rotatePoint( angle, rect.bottom_right ); } // Function: outputRectangle void outputRectangle( const Rectangle& rect ) { cout << "Rectangle " << left << setw(3) << rect.id << endl; cout << "Bottom left "; outputPoint( rect.bottom_left ); } // END ////////////////////////////// When I try to compile rect.cpp, I get the following error messages: g++ -c rect.cpp -o rect.o In file included from rect.cpp:7: rect.h:17: `rect' was not declared in this scope rect.h:17: variable or field `inputRectangle' declared void rect.h:18: type specifier omitted for parameter `Rectangle' rect.h:18: parse error before `&' token rect.h:19: parse error before `&' token In file included from rect.cpp:7: rect.h:21:7: warning: no newline at end of file rect.cpp:14: `rect' was not declared in this scope rect.cpp:15: variable or field `inputRectangle' declared void rect.cpp:15: redefinition of `int inputRectangle' rect.h:17: `int inputRectangle' previously defined here rect.cpp:15: syntax error before `{' token rect.cpp:18: syntax error before `>>' token rect.cpp:20: syntax error before `<<' token rect.cpp:21: `rect' was not declared in this scope rect.cpp:21: ISO C++ forbids declaration of `inputPoint' with no type rect.cpp:21: `int inputPoint' redeclared as different kind of symbol point.h:11: previous declaration of `void inputPoint(Point&)' rect.cpp:24: parse error before `return' rect.cpp:30: type specifier omitted for parameter `Rectangle' rect.cpp:30: parse error before `&' token rect.cpp: In function `void rotateRectangle(...)': rect.cpp:32: `angle' undeclared (first use this function) rect.cpp:32: (Each undeclared identifier is reported only once for each function it appears in.) rect.cpp:32: `rect' undeclared (first use this function) rect.cpp: At global scope: rect.cpp:40: parse error before `&' token rect.cpp:45:2: warning: no newline at end of file If I rename my 'Rectangle' struct to something else, everything is good to go. This begs the question as to whether another 'Rectangle' is defined? If so (or if not) how can I avoid these errors while still using Rectangle for the name of my struct? Thanks, Cameron |