I want to know how to use members from other files in main c++ code file?
I already know that we can put our declarations in header files.
Let me summarize my current knowledge and missing parts:
Example 1 - using a function from another file
other.cpp
int Add(int a,int b)
{
return a+b;
}
main.cpp
int Add(int,int); //the most important part
int main()
{
Add(12,2);
}
Example 2 - using a global variable from another file
other.cpp
int something=12;
main.cpp
extern int something; //the most important part
int main()
{
cout << something;
}
Question 1 - create an object from a class in another file???
other.cpp
class Rectangle
{
public:
int width;
int height;
int area() { return height*width }
};
main.cpp
int main()
{
Rectangle a; //gives me error,what should i do?
}