hi Folks!..
I want to ask how to compile c++ header files using g++ compiler i have written the following code for the class
Code:
#include <iostream>
using namespace std;
class Rectangle
{
private:
int w;
int h;
public:
Rectangle()
{
w=h=0;
}
void setDim(int w, int h)
{
this.w = w;
this.h = h;
}
void show()
{
cout<<"The Width is : "<<w<<"\nHeight is : "<<h;
}
};
Saved it with name "Rectangle.h" when i try to compile this file with g++ using command
[root@SERVER Code]# g++ Rectangle.h
Following msg is displayed.
g++: compilation of header file requested.
But it is not compiled.And when i try to include it so i may use this class in a program. like..
The code for main() function is like this......stored in file testMain.cpp
Code:
#include <iostream>
#include <Rectangle.h>
using namespace std;
int main()
{
Rectangle r1;
r1.setDim(10,20);
r1.show();
return 0;
}
when i compile this code with g++ with the following command...
[root@SERVER Code]# g++ testMain.cpp -o testMain
I get the following Errors
testMain.cpp:2:23: Rectangle.h: No such file or directory
testMain.cpp: In function `int main()':
testMain.cpp:8: `Rectangle' undeclared (first use this function)
testMain.cpp:8: (Each undeclared identifier is reported only once for each
function it appears in.)
testMain.cpp:8: parse error before `;' token
testMain.cpp:9: `r1' undeclared (first use this function)
Plz Tell me how to overcome these errors.... and more specificallly how to compile c++ header files.
Regards, JinBaba