I am implementing a static library in C++. The problem I have is that in the header file that goes with the library other header files are included. How do I wrap the library so that these files are not visible? For example, say I have this code:
//MyLib.h
#ifndef MyLib_h
#define MyLib_h
class Math
{
public:
// this method returns the mass of the Universe
static double CalcMassOfTheUniverse();
}
#endif
//MyLib.cpp
#include MyLyb.h
double Math::CalcMassofTheUniverse()
{
// do some complicated calculations here
return result;
}
Then I find that in order to calculate the mass of the Universe easier I have to have a variable of type UniverseObject:
//MyLib.h
#ifndef MyLib_h
#define MyLib_h
#include "UniverseObject.h"
class Math
{
public:
double string CalcMassOfTheUniverse();
private:
UniverseObject m_Universe; // used to calculate the mass
}
#endif
//MyLib.cpp
#include MyLib.h
double Math::CalcMassofTheUniverse()
{
// Use m_Universe to calculate mass of the Universe
return massOfTheUniverse;
}
The problem is that now in the header file I include "UniverseObject.h". I understand that this is necessary since the Math class uses it but is there a way to wrap the class in such a way that users do not know what headers I use and so on? I am asking this since it would be easier to give people only one header and the library instead of a bunch of headers.