c++98

What is “ANSI C++”?

无人久伴 提交于 2019-12-04 01:54:20
I've had someone tell me that C++98 was written under ANSI before being formally standardised as ISO/IEC 14882:1998. I know that ANSI was involved with C, but I can't seem to find much in the way of proof that the phrase "ANSI C++" is terribly accurate. Is "ANSI C++" a good description for C++98? Is "ANSI C++" a good description for subsequent versions of the C++ standard? Erik Initially, in '89, the standardization of C++ was handled by ANSI X3J16. Starting in '91 ISO WG21 joined in. You may want to read BS's A History of C++:1979-1991 . IMO, "ANSI C++" is just a leftover name; the language

g++ flag to only check syntax?

試著忘記壹切 提交于 2019-12-03 21:48:13
Is there a way to have g++ check for C++98 syntax when compiling but at the same time compile as if no -std= has been given ? My goal is to make sure that my source code stays C++98 but I don't want to prevent g++ from using any newer optimisation or trick. For the moment, I compile my projet twice, once with CXXFLAGS=-std=c++98 and one with a final empty CXXFLAGS for release. It looks like gcc 5 will have -Wc90-c99-compat and -Wc99-c11-compat , that something in that direction. You will have to run the compiler twice, but you can save compiletime on the -std=c++98 pass and avoid generating

Forward declarations and shared_ptr

别等时光非礼了梦想. 提交于 2019-12-03 12:25:43
I'm trying to refactor my code so that I use forward declarations instead of including lots of headers. I'm new to this and have a question regarding boost::shared_ptr. Say I have the following interface: #ifndef I_STARTER_H_ #define I_STARTER_H_ #include <boost/shared_ptr.hpp> class IStarter { public: virtual ~IStarter() {}; virtual operator()() = 0; }; typedef boost::shared_ptr<IStarter> IStarterPtr; #endif I then have a function in another class which takes an IStarterPtr object as argument, say: virtual void addStarter(IStarterPtr starter) { _starter = starter; } ... IStarterPtr _starter;

Why is std::list bigger on c++11?

痴心易碎 提交于 2019-12-03 09:30:46
with this code: #include <iostream> #include <list> int main() { std::cout << sizeof(std::list<void*>) << std::endl; }; I managed to notice that on GCC 4.7 the size of std::list<void*> on C++98 is 16 bytes, and its size on C++11 is 24 bytes. I was wondering what changed on std::list that made it bigger. C++11 requires list::size() to execute in constant time. GCC made this possible by adding the size as a data member . GCC did not do so for C++98 mode, because that would break binary compatibility. Don't mix code compiled in C++98 mode with code compiled in C++11 mode. It doesn't work. Update

May I use a constant number to choose a class at compile time, possibly using templates?

拜拜、爱过 提交于 2019-12-03 07:49:05
Let's say I have a constant value (possibly of some enum type). Let's say I have many classes A, B, D, etc. Can I have something like this? C<1> anInstanceOfA; //This will be of type A C<2> anInstanceOfB; //This will be of type B C<3> anInstanceOfD; //This will be of type D So, is it possible to select a class based on a constant number at compile time? The general problem is that I am trying to select a functor based on a table, in which the index is an enum. I would like to avoid polymorfism if possible. Edit: For this project I cannot use C++11, thanks anyway to who answered in that context

Is there a method to use gmpxx.h together with c++98?

走远了吗. 提交于 2019-12-02 19:45:56
问题 Because of my project I need to use c++98 and gmpxx.h: But even for a simple project, it doesn't work: #include <gmp.h> #include <gmpxx.h> int main() { int xrange=5,yrange=5,component=5; return 0; } The error message is: I tried using the following compiling methods libc++: support c++11 and thus work libstdc++: only support c++98 and do not work Is there a way to use c++98 to implement gmpxx? thank you :) Detail of errors when using c98++ to implement: The breaking line is: cout<<r<<endl;

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

爷,独闯天下 提交于 2019-12-02 18:57:36
What is the right way to initialize static data members in C++? I'm also interested in how it has changed from C++98, to C++11 to C++14. Here is an example: // bufferedOutput.h class BufferedOutput { // Static member declaration. static long bytecount; }; // bufferedOutput.cpp long BufferedOutput::bytecount = 50; Are there other ways to initialize static data members? 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

Is there a method to use gmpxx.h together with c++98?

こ雲淡風輕ζ 提交于 2019-12-02 10:57:34
Because of my project I need to use c++98 and gmpxx.h: But even for a simple project, it doesn't work: #include <gmp.h> #include <gmpxx.h> int main() { int xrange=5,yrange=5,component=5; return 0; } The error message is: I tried using the following compiling methods libc++: support c++11 and thus work libstdc++: only support c++98 and do not work Is there a way to use c++98 to implement gmpxx? thank you :) Detail of errors when using c98++ to implement: The breaking line is: cout<<r<<endl; But it works in c++11: The error report: 来源: https://stackoverflow.com/questions/25229930/is-there-a

Iterate over a std::vector in sorted order [closed]

蓝咒 提交于 2019-12-01 19:31:37
I receive from an API a vector of Foo as follows: std::vector<Foo> foos; I have then written a function called std::vector<std::string> getKeys(const std::vector<Foo>&) which iterates over the container and plucks out a key of type std::string for each Foo object. How would you iterate over the Foo objects in foos in sorted order, where sorting is done on the key and in a case insensitive manner. Additionally, I'd prefer not to make a sorted copy of foos since it is large in size. Here's my attempt, which works but I'm wondering if it can be done better. struct CaseInsensitiveComparitor { bool

C++98/03 reference collapsing and cv qualifiers

此生再无相见时 提交于 2019-12-01 17:00:40
问题 The code below compiles (gcc 4.7.2 or icc 13) and produces "1 2" output. Which means that const qualifier is dropped, i. e., f<int&> has the parameter type int& . Why does it happen? As I understand, according to §14.3.1.4: If a template-argument for a template-parameter T names a type “reference to cv1 S ”, an attempt to create the type “reference to cv2 T ” creates the type “reference to cv12 S ”, where cv12 is the union of the cv-qualifiers cv1 and cv2 . Redundant cv-qualifiers are ignored.