I'm trying to use pimpl idiom. In particular, the implementation class would implement another interface:
// public_class.h
class PublicClass
{
public:
/* public interfaces here */
private:
class _PublicClass_impl;
friend class _PublicClass_impl;
protected:
_PublicClass_impl * const _impl;
};
// public_class.cpp
class PublicClass::_PublicClass_impl : public SomeInterface
{
friend class PublicClass;
/* all sort of stuff ... */
};
My question is, what casts can be used in the following situation?
// some_other_class.h
class SomeOtherClass : private PublicClass
{
void some_function()
{
// definition of _PublicClass_impl is unknown
// thus, _impl is opaque
SomeInterface * interface = dynamic_cast<SomeInterface *>(_impl); //??
/* more code ... */
}
};
Would dynamic_cast work fine in this case? Are there any other types of cast that can be used in this case?