Pretty much is all in the question, but is there any way to get the encapsulation you get from using an opaque ptr with a template class? (My gut is "no", because the compiler has to be aware of everything at compile time)
Something like this, where MyClass should be exposed through a static library and MyClassImp is hidden.
//MyClass.h
template <typename T> MyClassImp;
template <typename T> MyClass
{
public:
MyClass();
void Foo();
private:
MyClassImp<T>* impl;
}
//MyClassImp.h
template <typename T> MyClassImp
{
public:
MyClassImp() {}
void Foo() {/*proprietary/complex stuff I want to hide*/}
}
//MyClass.cpp
template <typename T>
MyClass::MyClass()
{
impl = new MyClassImp();
}
template <typename T>
void MyClass::Foo() { impl->Foo(); }
This does not work because MyClass::Foo, hidden in the .cpp file, cannot be exposed without including the definition of MyClassImp, so you get a function missing error.