code:
struct example
{
int a = 0; // line 3
example()
{}
};
I am gettting data initializer is not allowed here error at Line 3
How to solve this?
code:
struct example
{
int a = 0; // line 3
example()
{}
};
I am gettting data initializer is not allowed here error at Line 3
How to solve this?
In C++
prior to C++11 standard, you cannot initialize value where you declare it, you have to do it with constructor:
struct example
{
// int a = 0; NOT ALLOWED
int a;
example() : a (0) {} // preferred way
/* NOT PREFERRED WAY
example() {
a = 0;
}
*/
}
EDIT: Thank to @user4581301 for the comments:
Here is initialization list
Here is why is initialization list preferred
How to solve this?
A few options: