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

Is it reasonable to use std::basic_string as a contiguous buffer when targeting C++03?

I’d consider it quite safe to assume that std::string allocates its storage contiguously. At the present time, all known implementations of std::string allocate space contiguously. Moreover, the current draft of C++ 0x (N3000) [Edit: Warning, direct link to large PDF] requires that the space be allocated contiguously (ยง21.4.1/5): The char-like objects in a basic_string object … Read more

Which Typesafe Enum in C++ Are You Using?

I’m currently playing around with the Boost.Enum proposal from the Boost Vault (filename enum_rev4.6.zip). Although it was never officially submitted for inclusion into Boost, it’s useable as-is. (Documentation is lacking but is made up for by clear source code and good tests.) Boost.Enum lets you declare an enum like this: BOOST_ENUM_VALUES(Level, const char*, (Abort)(“unrecoverable problem”) … Read more

Can virtual functions have default parameters?

Virtuals may have defaults. The defaults in the base class are not inherited by derived classes. Which default is used — ie, the base class’ or a derived class’ — is determined by the static type used to make the call to the function. If you call through a base class object, pointer or reference, … Read more

What are the differences between C-like, constructor, and uniform initialization?

First, I would recommend looking at the following talk by Herb Sutter, in which he gives some recommendations about the subject. The brace-initialization discussion starts at around 23:00. When you are talking about primitive data types, all 3 yield the same result. I personally prefer sticking with the old int x = 0 syntax, but … Read more

How can I pass a class member function as a callback?

This is a simple question but the answer is surprisingly complex. The short answer is you can do what you’re trying to do with std::bind1st or boost::bind. The longer answer is below. The compiler is correct to suggest you use &CLoggersInfra::RedundencyManagerCallBack. First, if RedundencyManagerCallBack is a member function, the function itself doesn’t belong to any … Read more