I have just started using std::variant
in my projects. I have a doubt. What will the destructor of std::variant
do in the code shown below. Variant holds a void*
data. Once variant goes out of scope, I think it will only free the memory of void*
but not the actual object the pointer was pointing to. So there will be memory leak in this case. I would like to know if my understanding is correct or not.
#include <iostream>
#include <memory>
#include <variant>
using namespace std;
class A {
public:
~A(){
cout<<"Destructor called"<<endl;
}
};
int main() {
std::variant<void*> data;
A* b = new A();
data = (void*)b;
return 0;
}