Original Post
My GPGPU library currently contains two tied interfaces: Device, and Shader. The Shader does not know anything about Devices, but a Device may create (returned by a member function) and execute (as argument to a member function) Shaders. The Shader and Device are then implemented for different situations, such as CUDA_Kernel : public Shader and CUDA_Device : public Device. Obviously, a CUDA_Kernel contains CUDA-specific data (such as a CUmodule reference) which are not part of Shader and yet are required by CUDA_Device for execution. My problem (and it's a classic one) is about letting CUDA_Device access CUDA-specific members of CUDA_Kernel, when it receives a Shader through its overridden Device base class functions (and throw an exception if the Shader isn't the expected CUDA_Kernel). I should mention that my language does not support multiple dispatch in any way which would respect the open-closed principle. What solutions do you propose? Is there any elegant solution I might have overlooked, or is casting Shader to CUDA_Kernel the only possible one?