Why does the following not compile?
class A {
public:
A(int a) : a_{a} {}
private:
int a_;
};
Why does the following not compile?
class A {
public:
A(int a) : a_{a} {}
private:
int a_;
};
Copyright © 2021 Jogjafile Inc.
Because you're most probably compiling the shown code, with Pre-C++11 standard version.
The curly braces around
a
in your example, is a C++11 feature.To solve this you can either compile your program with a C++11(or later) version or use parenthesis
()
as shown below:Pre-C++11
C++11 & Onwards