I'm curious to know why class members cannot be initialized using () syntax? Consider the following example:
#include <iostream> class test { public: void fun() { int a(3); std::cout<<a<<'\n'; } private: int s(3); // Compiler error why??? }; int main() { test t; t.fun(); return 0; }
The program does not work in compilation and gives the following errors.
11 9 [Error] expected identifier before numeric constant 11 9 [Error] expected ',' or '...' before numeric constant
Why? What is the reason? What does the C ++ standard say about initializing class data members? Your help is greatly appreciated. thanks
source share