A class A
is defined and implemented. Later it's declared as a struct as the template argument of std::unique_ptr
. The compiler(g++10.1) complains nothing about it and the program can be run.
#include <iostream>
#include <string>
#include <memory>
class A
{
public:
std::string info = "Hello World!";
};
int main()
{
std::unique_ptr<struct A> a{new A};
std::cout << a->info << "\n";
return 0;
}
If I define a without the new A
std::unique_ptr<struct A> a;
The code can still be compiled but there is a segmentation fault during runtime. So why is this possible?