This is an incorrect declaration:
using Foo::ImplementationDetail = Library::SomeStruct;
using
doesn't work this way. In C++11 using
cannot create an alias for a name in one namespace to a name in another namespace. In C++03, all using
does is bring some other namespace in to global visibility in the current translation unit. It's not used to create aliases in C++03, as you seem to want to do here.
pimpl is the de-facto method for doing what you're trying to do, but in your header file instead of trying to use a ImplementationDetail*
, I would use a simple void*
. Using a void*
in this manner is guaranteed to be correct according to the Standard:
class Foo {
private:
void * pImpl;
Use static_cast
2 to go from a void*
to your actual type:
void Foo::Bar()
{
Library::SomeStruct* thingy = static_cast <Library::SomeStruct*> (pImpl);
// ...
}
You can avoid using the void*
in a conformant way by forward-declaring your library type:
namespace Library
{
struct SomeStruct;
};
class Foo
{
private:
Library::SomeStruct* pStruct;
};
And then no ugly cast is needed in the implementation.
2 Use static_cast
: Or reinterpret_cast