Hi,
I have a C++ project defined with 3 source files named CRectangle.cpp, CVector.cpp and main.cpp. The main.cpp conains the entry point main() function and the other two files contains the corresponding classes defined in them (CRectangle and CVector classes). The source codes of these files are given below. The compiler is VS2005/2008.
When I try to build the project it gives me the error CRectangle and CVector as undeclared identifier in main.cpp. I hope that I am missing some steps in the linking. Can anybody help to enlighten? Thanks.
main.cpp:
-----------
#include <iostream>
using namespace std;
int main () {
CRectangle a, *b, *c;
CRectangle *d = new CRectangle[2];
b = new CRectangle;
c =&a;
a.set_values(1,2);
b->set_values(3,4);
CRectangle.cpp:
-----------------
class CRectangle {
int width, height;
public:
void set_values (int, int);
int area (void) {return (width*height);}
};
void CRectangle::set_values(int a, int b) {
width=a;
height=b;
}
CVector.cpp:
--------------
class CVector {
public:
int x, y;
CVector();
CVector(int, int);
CVector operator + (CVector);
};
CVector::CVector(int a, int b) {
x = a;
y = b;
}
CVector CVector::operator+ (CVector param) {
CVector temp;
temp.x = x + param.x;
temp.y = y + param.y;
return (temp);
}
Thanks a lot for your quick reply and the link. I added a header file for class definitions and I included it in all 3 cpp files and now it works. I work mainly with Java recent years hence stuck with this basic concept. Thanks again.