I have classes who handle (Vulkan) ressources, lets call them
VulkanInstance
and VulkanDevice
.
My Master
class owns both of these
class Master {
VulkanInstance instance_;
VulkanDevice device_;
reset();
}
in my reset
function i want to delete the current instance
and device
and create a new one.
I thought of the following conditions:
device_
must be destroyed beforeinstace_
can be destroyed, becausedevice_
depends oninstance_
instance_
must be created beforedevice_
can be createddevice_
andinstance_
can't be copied, however they can be constructed, move contructed and move assigned- i want to create a new
VulkanInstance
andVulkanDevice
before deleting the oldinstance_
anddevice_
. So that when i get errors during construction of the new elements i still have the old valid classes left.
My question is: How should i design the reset
function. Can it be realised without using pointers
/ std::unique_ptr
to VulkanInstance
or VulkanDevice
.
I though about something like this
// PSEUDO CODE
Master::reset() {
VulkanInstance new_instance {};
VulkanDevice new_device {};
device_ = new_device; //use move here and destruct old device_ Dont use copy constructor
instance_ = new_instance; //use move here and destruct old device_ Dont use copy constructor
}