Original Post
Hello! I've been thinking for a couple of days on this one but I can't find an elegant solution. Assume that there is an interface class which specifies 'a device'. Most probably there are many particular device implementations. I am looking for a way to 'create a device' selected by the user while not requiring user to mess around with library code (i.e. no switch statement selecting an implementation). Here is what I'd like to achieve : The second major problem is - how to limit the code user to use only create/destroyDevice and forbid any other way of Device creation? One solution is to make createDevice/destoryDevice friend functions in deviceWin32::Device but it doesn't seem like an ideal solution. Thanks in advance!
// We've got a pointer to a concrete device
deviceWin32::Device *pDevice;
// There is a global function (perhaps template?) which creates the device
// IMPORTANT : this should be the ONLY way to create device
createDevice<deviceWin32::Device>(pDevice);
// There is a global function which destroys the device
// IMPORTANT : this shoud be the ONLY wat to destroy device
destoryDevice<deviceWin32::Device)(pDevice);