I have a bunch of simple structures inherited from some interface, and I cannot use list initialization for them:
#include <iostream>
#include <string>
class Foo
{
public:
virtual void write() = 0;
};
struct Bar : public Foo // if I remove this inheritance, it will compile
{
int num;
void write()
{
std::cout << "num = " << num;
}
};
int main()
{
Bar b{ 11 }; // error here
b.write();
return 0;
}
Edit: compiler outputs with several warnings and error:
<source>:21:15: error: no matching function for call to 'Bar::Bar(<brace-enclosed initializer list>)'
21 | Bar b{ 11 };
| ^
<source>:10:8: note: candidate: 'Bar::Bar()'
10 | struct Bar : public Foo // if I remove this inheritance, it will compile
| ^~~
<source>:10:8: note: candidate expects 0 arguments, 1 provided
<source>:10:8: note: candidate: 'constexpr Bar::Bar(const Bar&)'
<source>:10:8: note: no known conversion for argument 1 from 'int' to 'const Bar&'
<source>:10:8: note: candidate: 'constexpr Bar::Bar(Bar&&)'
<source>:10:8: note: no known conversion for argument 1 from 'int' to 'Bar&&'