As far as I understand the RAII idiom when applied to the resources needed by the class (and please correct me if I am mistaken), the class requiring the resource must determine the member of the corresponding type, and its destructor will be called automatically when the instance of the used class is destroyed, for example:
class Skybox { public: Skybox() : tex_(...) {} private: Texture tex_; };
Besides using a smart pointer to allocate a resource on the heap, how can this template be applied if a resource member requires some code to be executed in the Skybox constructor before the resource is initialized? For instance:
class Skybox { public: Skybox(const std::string& fileName); private: Texture tex_; } Skybox::Skybox(const std::string& fileName) {
Update: the Texture class requires that all initialization be performed in its constructor (i.e. the Texture::Init() method is available)
source share