Unlike C++ 98, the below kind of initialization syntax is valid now.
==
class A {
int a = 7;
int b = 5;
HashingFunction hash_algorithm{"MD5"};
std::string s{"Constructor run"};
static const int THE_LIMIT = 7; // the classic one; valid in C++98 too
public:
A() {}
A(int a_val) : a(a_val) {} // here a will not be init by 7. but by cstor time a_val
A(D d) : b(g(d)) {}
};
==
In C++ 98 only static const basic data typed items are only allowed initializer.
refer: http://www.stroustrup.com/C++11FAQ.html#delegating-ctor
.veenusNotes 2017
==
class A {
int a = 7;
int b = 5;
HashingFunction hash_algorithm{"MD5"};
std::string s{"Constructor run"};
static const int THE_LIMIT = 7; // the classic one; valid in C++98 too
public:
A() {}
A(int a_val) : a(a_val) {} // here a will not be init by 7. but by cstor time a_val
A(D d) : b(g(d)) {}
};
==
In C++ 98 only static const basic data typed items are only allowed initializer.
refer: http://www.stroustrup.com/C++11FAQ.html#delegating-ctor
.veenusNotes 2017
Comments
Post a Comment