I am developing a library. I have interface class that would be called from outside.
I have also an internal engine that should not be called from outside.
As I read here and there, I should hide the internal engine class and not even populate its header. Since I have the following structure:
interface.hpp:
#include "engine.hpp"
class interface{
private:
enigne eng;
};
interface.cpp:
#include "engine.hpp"
//code that uses member variables and functions from eninge
engine.hpp:
class engine{};
To solve the problem of populating "engine.hpp", I should change the code to:
interface.hpp:
class engine;
class interface{
private:
some_smart_pointer<enigne> eng_ptr;
};
interface.cpp:
#include "engine.hpp"
//code that uses member variables and functions from eninge
enigne.hpp:
class engine{};
This solved the problem. However, from now engine
is allocated dynamically. All its member variables are in the free store.
I can not understand that I have to change my design and allocate engine on the free store for solving the problem of hiding implementation details. Is there a better solution?
P.S. I am not asking about why this solution works. I know it's about knowing the size of engine class is mandatory if I would leave it on stack. My question is about asking for a different design that may solve the problem.
EDIT:
Both interface
and engine
have member variables.