c++03

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

回眸只為那壹抹淺笑 提交于 2019-11-26 06:44:36
问题 I know that in C++03, technically the std::basic_string template is not required to have contiguous memory. However, I\'m curious how many implementations exist for modern compilers that actually take advantage of this freedom. For example, if one wants to use basic_string to receive the results of some C API (like the example below), it seems silly to allocate a vector just to turn it into a string immediately. Example: DWORD valueLength = 0; DWORD type; LONG errorCheck = RegQueryValueExW(

Can C++ code be valid in both C++03 and C++11 but do different things?

非 Y 不嫁゛ 提交于 2019-11-26 06:09:38
问题 Is it possible for C++ code to conform to both the C++03 standard and the C++11 standard, but do different things depending on under which standard it is being compiled? 回答1: The answer is a definite yes. On the plus side there is: Code that previously implicitly copied objects will now implicitly move them when possible. On the negative side, several examples are listed in the appendix C of the standard. Even though there are many more negative ones than positive, each one of them is much

Can virtual functions have default parameters?

旧街凉风 提交于 2019-11-26 03:36:59
问题 If I declare a base class (or interface class) and specify a default value for one or more of its parameters, do the derived classes have to specify the same defaults and if not, which defaults will manifest in the derived classes? Addendum: I\'m also interested in how this may be handled across different compilers and any input on \"recommended\" practice in this scenario. 回答1: Virtuals may have defaults. The defaults in the base class are not inherited by derived classes. Which default is

Which Typesafe Enum in C++ Are You Using?

早过忘川 提交于 2019-11-26 02:50:51
问题 It is common knowledge that built-in enums in C++ are not typesafe. I was wondering which classes implementing typesafe enums are used out there... I myself use the following \"bicycle\", but it is somewhat verbose and limited: typesafeenum.h: struct TypesafeEnum { // Construction: public: TypesafeEnum(): id (next_id++), name(\"\") {} TypesafeEnum(const std::string& n): id(next_id++), name(n) {} // Operations: public: bool operator == (const TypesafeEnum& right) const; bool operator != (const

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

ε祈祈猫儿з 提交于 2019-11-26 01:07:13
问题 To the best of my knowledge, there are three ways to initialize a variable in C++. int x = 0; // C-like initialization int x (0); // Constructor initialization int x {0}; // Uniform initialization The uniform initialization was brought on for C++11 to provide a more uniform syntax for initializing different types of variables, which required different syntax in C++03. What are the differences between C-like, constructor, and uniform initialization? And should I always use the uniform

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

不问归期 提交于 2019-11-25 23:21:36
问题 I\'m using an API that requires me to pass a function pointer as a callback. I\'m trying to use this API from my class but I\'m getting compilation errors. Here is what I did from my constructor: m_cRedundencyManager->Init(this->RedundencyManagerCallBack); This doesn\'t compile - I get the following error: Error 8 error C3867: \'CLoggersInfra::RedundencyManagerCallBack\': function call missing argument list; use \'&CLoggersInfra::RedundencyManagerCallBack\' to create a pointer to member I