How to initialize class instance with initializer_list if class has base with virtual methods c++? I want to avoid writing constructors and use "lazy" way to initialize class like X x{"Some string"};. But I got
error: no matching function for call to ‘X::X(<brace-enclosed initializer list>)’
Is any way to simply initialize X instance without significant changing of classes?
struct Y
{
virtual ~Y() = 0;
};
struct X : public Y
{
string msg;
virtual ~X() = default;
};
int main()
{
X x{"Some string"};
return 0;
}