We are developping an embedded project, where we use C++14 and PIMPL for the OS-Abstraction. So we have Task-PIMPL-Interface which gets implemented in the referenced operating-system-SDK. Currently a small additional effort must be done because this class needs extra private attributes which unfortunately need to be accessed via a function directly.
This is needed because some of the Task-functions which are called from our initialization-management may be allocated at a different heap (overwrote malloc with our own heap-management), since we need to support different heaps at different places (and peripherals). And the task should keep info about the heap it was allocated in the first place. We will then store the initially used heap inside a task-attribute and check this when calling the other task-functions from outside to make sure any allocation that is done inside those functions is done at the correct heap.
Since I know all private variables should reside inside the Impl I am concerned that what I want to achieve would work. Since private member variables need to be initialized this would mean I need to recompile and modify the Impls as well. But C++11 brought default member initializer into the game.
so my guess was something like this:
struct Attributes
{
uint16_t val1;
uint16_t val2;
};
class PimplClass
{
public:
void callFuncA(); // in Impl
/* access to the private attributes */
Attributes& getAttr()
{ return attr_; }
void setAttr( Attributes& attr )
{ attr_ = attr; }
private:
class PimplClassImpl;
PimplClassImpl* pimpl_;
/* the private attributes */
Attributes attr_ = { 0, 0};
}
How does that behave to the interface and the implementation? Is the compile-firewall broken with that? We cannot directly tell if that makes a difference for us, since the Impl gets compiled anyway currently since our build-setup does not compile the Impls separately but we need to ensure the functionality for future build-setups, because then we may just link against a compiled lib.
Thanks!