This is a very basic thing that I am just wondering about. When I #inlcude "string.h" in my header file for a class, why can I also use strings in my .cpp file for the class. Why/How are included files (i think they are files?) passed down to the .cpp file for the class?
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <iostream>
#include "string.h"
usingnamespace std; // *** this is bad
class Employee
{
public:
Employee(string empName, int id, string dept, string pos);
protected:
private:
string name;
int idNumber;
string department;
string position;
};
#endif // EMPLOYEE_H
would look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
///// contents of the file iostream are preprocessed and inserted here ////////////////
///// contents of file string.h are preprocessed and inserted here ////////////////
usingnamespace std;
class Employee
{
public:
Employee(string empName, int id, string dept, string pos);
protected:
private:
string name;
int idNumber;
string department;
string position;
};
If we now have #include "Employee.h" , the effect is as if the directive was replaced by the preprocessed contents of employee.h
(Into which the preprocessed contents of "string.h" were already inserted.)
Thanks for the replies, that makes sense, I am used to having to copy over import or using statements in Java or C#, so this is something I will have to get used to.