What is the correct way to initialize static data members in C++ (98, 11 and 14)

The rules have always been as follows: A const static data member (SDM) of integral or enumeration type can be initialised in class with a constant expression. A constexpr SDM must be initialised in class with a constant expression. C++17 no longer requires an initializer when the default constructor initialises every member. Also, constexpr SDMs … Read more

Why does C++’s “using namespace” work the way it does?

Quoting an excerpt from C++ Primer (5th Edition) section “18.2.2. Using Namespace Members” The scope of names introduced by a using directive is more complicated than the scope of names in using declarations. As we’ve seen, a using declaration puts the name in the same scope as that of the using declaration itself. It is … Read more

Why are default template arguments only allowed on class templates?

It makes sense to give default template arguments. For example you could create a sort function: template<typename Iterator, typename Comp = std::less< typename std::iterator_traits<Iterator>::value_type> > void sort(Iterator beg, Iterator end, Comp c = Comp()) { … } C++0x introduces them to C++. See this defect report by Bjarne Stroustrup: Default Template Arguments for Function Templates … Read more

Default, value and zero initialization mess

C++14 specifies initialization of objects created with new in [expr.new]/17 ([expr.new]/15 in C++11, and the note wasn’t a note but normative text back then): A new-expression that creates an object of type T initializes that object as follows: If the new-initializer is omitted, the object is default-initialized (8.5). [ Note: If no initialization is performed, … Read more

Are Exceptions in C++ really slow

The main model used today for exceptions (Itanium ABI, VC++ 64 bits) is the Zero-Cost model exceptions. The idea is that instead of losing time by setting up a guard and explicitly checking for the presence of exceptions everywhere, the compiler generates a side table that maps any point that may throw an exception (Program … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)