B
Busin
class AA
{
public:
const int n;
};
int main()
{
AA a;
....
}
This code gives error: "C2512: 'AA' : no appropriate default constructor
available."
Then adding a constructor fixes the error.
class AA
{
public:
const int n;
AA(int m) : n(m) {}
};
int main()
{
AA a(1);
...
}
Can someone elaborate why with a const member variable, the default
constructor isn't enough? Thanks!
{
public:
const int n;
};
int main()
{
AA a;
....
}
This code gives error: "C2512: 'AA' : no appropriate default constructor
available."
Then adding a constructor fixes the error.
class AA
{
public:
const int n;
AA(int m) : n(m) {}
};
int main()
{
AA a(1);
...
}
Can someone elaborate why with a const member variable, the default
constructor isn't enough? Thanks!