I'm writing a simple practice program in c++ on my desktop with the Ubuntu OS. This is my main.cpp, with the main() method:
#include "miscClass1.h"
#include <iostream>
using namespace std;
int main(){
miscClass1 A(3, 5);
cout << A.getX() << endl;
}
this is the header file for my misc class where I just define a few simple fields and functions(misClass1.h)
#ifndef MISCCLASS1_H
#define MISCCLASS1_H
class miscClass1 {
int X;
int Y;
public:
miscClass1(int x, int y);
int addXY();//adds the two variables x and y
int getX();
int getY();//accessors
void setX(int x);
void setY(int y);//mutators
};
#endif
and this is the source file for the header file of the class(misClass1.cpp):
#include "miscClass1.h"
miscClass1::miscClass1(int x, int y)
{
X = x;
Y = y;
}
int miscClass1::addXY()
{
return (X + Y);
}
int miscClass1::getX()
{
return (X);
}
int miscClass1::getY()
{
return (Y);
}
void miscClass1::setX(int x)
{
X = x;
}
void miscClass1::setY(int y)
{
Y = y;
}
This works, but I had to use the command:
$g++ main.cpp misClass1.cpp
While compiling, so if I ever had to compile a serious program with several classes/libraries, each stored in their own .cpp file, I would need to include each and every one of them if even if there were hundreds or thousands, which would be unattainable. How do I more efficiently compile my program, without calling every single file while compiling? I'd also like to know if anything else I'm doing in the program is bad practice.