c++98

c++ array zero-initialization: Is this a bug, or is this correct?

倖福魔咒の 提交于 2020-01-01 04:27:08
问题 Note: We are speaking about (supposedly) C++98 compliant compilers, here. This is not a C++11 question. We have a strange behavior in one of our compilers and we're not sure if this is Ok or if this is a compiler bug: // This struct has a default constructor struct AAA { AAA() : value(0) {} int value ; } ; // This struct has a member of type AAA and an array of int, both surrounded // by ints struct BBB { int m_a ; AAA m_b ; int m_c ; int m_d[42] ; } ; When BBB is initialized as such: BBB bbb

Using template typename in a nested function template

冷暖自知 提交于 2019-12-25 09:32:54
问题 Alright, I'm struggling with templates. In this question I learned, that it is not possible to pass a type specifier to a function at all, so my next approach is passing the type inside <> . Imagine a function template foo<U>() , which is member function of a template class A . So if I create an Object A<T> a I can call a.foo<U>() with any type. How do I have to write an equivalent function template so I can pass a and U like wrappedFoo<U>(a) ? IMPORTANT Needs to be C++98 compliant 回答1: You

json string with utf16 char cannot convert from 'const char [566]' to 'std::basic_string<_Elem,_Traits,_Ax>'

被刻印的时光 ゝ 提交于 2019-12-25 09:00:34
问题 I have json that needs to test a string with a utf16 wide char in it but I get the following error message: \..\test\TestClass.cpp(617): error C2440: 'initializing' : cannot convert from 'const char [566]' to 'std::basic_string<_Elem,_Traits,_Ax>' with 2> [ 2> _Elem=wchar_t, 2> _Traits=std::char_traits<wchar_t>, 2> _Ax=std::allocator<wchar_t> 2> ] 2> No constructor could take the source type, or constructor overload resolution was ambiguous This is my json: static std::wstring& BAD_JSON5

What's the C++98 equivalent of the auto iterator reference?

六月ゝ 毕业季﹏ 提交于 2019-12-24 14:00:19
问题 My development environment has RHEL 5.8 which does not support GCC 4.8+ modern (C++11+) compilers. I anticipate that someday we'll get there, so I have a header file where I define macros based on C++11 support levels so I can do something like this: #if defined(CPP11_auto_type_inference) && defined(CPP11_range_based_for_loops) for (auto vit : args) #else std::vector<std::string>::const_iterator vit, vend; for (vend=args.end(),vit=args.begin(); vit != vend; ++vit) #endif { // process

Meyers Singleton thread safe with C++-98

拈花ヽ惹草 提交于 2019-12-24 10:47:37
问题 Currently I have this implementation of the meyer singleton: class ClassA { public: static ClassA& GetInstance() { static ClassA instance; return instance; } private: ClassA::ClassA() {}; // avoid copying singleton ClassA(ClassA const&); void operator = (ClassA const&); }; Now I need some improvements to getting this code thread safe in C++-98 and VS-2008?! Thanks! PS: What is unclear? You see the tags visual-studio-2008 and c++-98 -> so the target OS is Windows! I also don't understand why I

Get the size of a member variable [duplicate]

独自空忆成欢 提交于 2019-12-24 01:13:22
问题 This question already has answers here : Does not evaluating the expression to which sizeof is applied make it legal to dereference a null or invalid pointer inside sizeof in C++? (3 answers) Is sizeof(*ptr) undefined behavior when pointing to invalid memory? (6 answers) Does the 'offsetof' macro from <stddef.h> invoke undefined behaviour? (6 answers) Why doesn't my program seg fault when I dereference a NULL pointer inside of malloc? (4 answers) Closed last year . There was a bug in g++-4.1

std::cout usage in constructors of objects with static storage duration

我的未来我决定 提交于 2019-12-23 12:55:59
问题 Is it safe to use std::cout in constructors of objects with statc storage duration in C++98 / C++03? It seems from this answer that it isn't but it doesn't include any quotes from the standard. Is it only safe to do that in C++11 and C++14? 回答1: From C++14 (N3797), §27.4p2: The objects are constructed and the associations are established at some time prior to or during the first time an object of class ios_base::Init is constructed, and in any case before the body of main begins exe- cution

gcc using c++11 standard even though 98 explicitly specified

喜你入骨 提交于 2019-12-23 04:49:10
问题 I'm getting a strange error I suspect has to do with my system configuration. I am compiling/linking a trivial c++ program using g++ --version = g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 . The default language standard is documented to be c++98, yet even with the -std=c++98 option specified, I am seeing c++11 symbols in the output .o file . This is my test.cpp: #include <string> int main() { std::string str = "Hello World!"; return 0; } Here are my compile and link commands (with

Where does the C++98 standard specify when a call to a static member is dependent within a template?

十年热恋 提交于 2019-12-22 08:38:55
问题 Compiling with Clang 3.0 -std=c++98, the following code is accepted: template<int> struct I { typedef int Type; }; template<class> struct S { static int f(int); //static int f(int*); // implicitly instantiates I<sizeof(int)> typedef I<sizeof(f(0))>::Type Type; }; S<int>::Type s; Uncommenting the overload of 'f' causes Clang to report an error "missing 'typename' prior to dependent type name". G++ 4.8 reports the same error with or without the overload. msvc10 does not give any errors with or

std::copy/memcpy/memmove optimizations

二次信任 提交于 2019-12-21 11:25:36
问题 I looked into the GCC STL (4.6.1) and saw that std::copy() uses an optimized version in case the builtin __is_trivial() evaluates to true . Since the std::copy() and std::reverse_copy() templates are very useful for copying elements in arrays, I would like to use them. However, I have some types (which are results of template instantiations) that are structs that contain some trivial values, no pointers and have no copy constructor or assignment operator. Is G++ smart enough to figure out