I pursued the PImpl design to avoid having to export STL from my dynamic library.
Old:
//In header file
class Foo{
public:
const map<char, char>& getMap() {return _map;}
private:
map<char, char> _map;
};
New:
//In header file
class Foo{
public:
Foo();
~Foo();
const map<char, char>& getMap();
private:
struct Impl;
Impl* _pimpl;
};
//In implementation file
struct Foo::Impl{
map<char, char> _map;
}
Foo::Foo(): _pimpl(new Impl){}
Foo::~Foo(){delete _pimpl;}
const map<char, char>& Foo::getMap(){return _pimpl->_map;}
However the clear issue is that I still have to export the map
as part of my library. I don't want to stop returning STL, but I don't see a way around it. Is there another paradigm which will still let me return STL but not have to export it?