# Libs, headers and external libs.

## Recommended Posts

CableGuy    1335
Hi. I have created a library to use FreeType and I have a problem:
class FontResource
{
friend class Renderer;
public:
FontResource();

private:
vector<Glyph> glyph;
FontPage *page;
FT_Face face;
int size;
};


As you can see I need to store FT_Face which is part of FreeType, which forces the users of my code also to include the FreeType headers. One way around it that I came up with is to store a void* and cast it in the source but that's too much hacky... Any ideas how to sort this out? Thanks.

##### Share on other sites
CableGuy    1335
If I wasn't clear enough just say so...

##### Share on other sites
Aardvajk    13207
Pimpl.

Basic idea is, using a different example:

lib.h
class Texture{private:    class Imp; Imp *i; // forward declaration, can only use pointers and referencespublic:    Texture();    ~Texture();};

lib.cpp
#include <d3d9.h>class Texture::Imp{public:    Imp() : Ptr(0) { }    ~Imp(){ if(Ptr) Ptr->Release(); }    IDirect3DTexture9 *Ptr;}Texture::Texture(){    i=new Imp(); i->Ptr=CreateTextureSomehow();}Texture::~Texture(){    delete i;}

This way, users including lib.h do not need to include, or even be aware of, d3d9.h or have any of its symbols dumped into global scope. Indeed you could change the implementation to use OpenGL and you would only have to recompile the library file and relink the project that uses it.

The link at the top will explain in far more detail.

##### Share on other sites
Kylotan    9860
Or you can use a pointer to an FT_Face. You don't need to include the FreeType header for that, but you do need to do some extra memory management for it.

CableGuy    1335
Thanks.