I am curious to know that why class' data members can't be initialized using () syntax? Consider following example:
#include <iostream>
class test
{
public:
void fun()
{
int a(3);
std::cout<<a<<'
';
}
private:
int s(3); // Compiler error why???
};
int main()
{
test t;
t.fun();
return 0;
}
The program fails in compilation & gives following errors.
11 9 [Error] expected identifier before numeric constant
11 9 [Error] expected ',' or '...' before numeric constant
Why? What is the reason? What the C++ standard says about initialization of class data members?
Your help is greatly appreciated. Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…