c++03

Calling delete on NULL pointers - C++03 vs C++11

情到浓时终转凉″ 提交于 2019-11-26 21:28:57
问题 In the C++03 Standard, I see: 5.3.5 Delete 2 If the operand has a class type, the operand is converted to a pointer type by calling the above-mentioned conversion function, and the converted operand is used in place of the original operand for the remainder of this section. In either alternative, if the value of the operand of delete is the null pointer the operation has no effect. In the first alternative ( delete object ), the value of the operand of delete shall be a pointer to a non-array

Why was the restriction on the comma operator being in a constant expression removed in C++11?

徘徊边缘 提交于 2019-11-26 20:52:25
问题 Recently when answering a question I realized that the comma operator is allowed in a constant expression in C++11 as long as the expression is surrounded by () , for example: int a[ (1, 2) ] ; Pre C++11 it is forbidden to use the comma operator in a constant expression, from the draft pre C++11 standard section 5.19 Constant expressions which says ( emphasis mine ): [...]In particular, except in sizeof expressions, functions, class objects, pointers, or references shall not be used, and

Default, value and zero initialization mess

人走茶凉 提交于 2019-11-26 18:48:57
问题 I am very confused about value- & default- & zero-initialization. and especially when they kick in for the different standards C++03 and C++11 (and C++14 ). I am quoting and trying to extend a really good answer Value-/Default-/Zero- Init C++98 and C++03 here to make it more general as it would help a lot of users if somebody could help fill out the needed gaps to have a good overview about what happens when? The full insight by examples in a nutshell: Sometimes the memory returned by the new

Purpose of Trigraph sequences in C++?

◇◆丶佛笑我妖孽 提交于 2019-11-26 18:25:14
According to C++'03 Standard 2.3/1: Before any other processing takes place, each occurrence of one of the following sequences of three characters (“trigraph sequences”) is replaced by the single character indicated in Table 1. ---------------------------------------------------------------------------- | trigraph | replacement | trigraph | replacement | trigraph | replacement | ---------------------------------------------------------------------------- | ??= | # | ??( | [ | ??< | { | | ??/ | \ | ??) | ] | ??> | } | | ??’ | ˆ | ??! | | | ??- | ˜ | ---------------------------------------------

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

♀尐吖头ヾ 提交于 2019-11-26 18:02:58
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? example 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 less likely to occur. String literals #define u8 "abc" const char* s = u8"def"; // Previously "abcdef"

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

扶醉桌前 提交于 2019-11-26 17:47:53
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( hWin32, value.c_str(), NULL, &type, NULL, &valueLength); if (errorCheck != ERROR_SUCCESS)

Which Typesafe Enum in C++ Are You Using?

ぃ、小莉子 提交于 2019-11-26 12:06:48
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 TypesafeEnum& right) const; bool operator < (const TypesafeEnum& right) const; std::string to_string()

Do these members have unspecified ordering?

佐手、 提交于 2019-11-26 11:25:32
问题 A colleague told me that, in the following type, all members have unspecified ordering in memory (relative to one another). I doubt this, because they all have the same access level. Who is correct? struct foo { public: int x; public: int y; public: int z; }; 回答1: Your colleague is correct for C++03: [C++03: 9.2/12]: Nonstatic data members of a (non-union) class declared without an intervening access-specifier are allocated so that later members have higher addresses within a class object.

initialize a const array in a class initializer in C++

百般思念 提交于 2019-11-26 11:20:41
I have the following class in C++: class a { const int b[2]; // other stuff follows // and here's the constructor a(void); } The question is, how do I initialize b in the initialization list, given that I can't initialize it inside the body of the function of the constructor, because b is const ? This doesn't work: a::a(void) : b([2,3]) { // other initialization stuff } Edit: The case in point is when I can have different values for b for different instances, but the values are known to be constant for the lifetime of the instance. Like the others said, ISO C++ doesn't support that. But you

Is there any reason to use the &#39;auto&#39; keyword in C++03?

泪湿孤枕 提交于 2019-11-26 09:06:55
问题 Note this question was originally posted in 2009, before C++11 was ratified and before the meaning of the auto keyword was drastically changed. The answers provided pertain only to the C++03 meaning of auto -- that being a storage class specified -- and not the C++11 meaning of auto -- that being automatic type deduction. If you are looking for advice about when to use the C++11 auto , this question is not relevant to that question. For the longest time I thought there was no reason to use