Why doesn’t std::make_shared
work anymore when the class Widget
inherits class enable_shared_from_this
?
Here is the code snippet:
#include<memory>
#include<vector>
#include<iostream>
class Widget:public std::enable_shared_from_this<Widget>
{
public:
std::vector<int> vec;
int var;
};
int main()
{
auto wp{std::make_shared<Widget>()};
//auto wp1{std::make_shared<Widget>(std::vector{1,2,3}, 9)}; //why his line compiles if class Widget does not inherit class enable_shared_from_this<Widget>
}
What's more, auto wp1{std::make_shared<Widget>(std::vector{1,2,3}, 9)};
works well if you remove the inheritance.
UPDATED: Both the aforementioned code snippet do not compile with clang.
TED's answer:
It works indeed. But I still don't know why there is a constructor added by
enable_shared_from_this
?