I've been working out of Sam's C++ book. Everything is going well, however I've gotten stuck with the keyword 'constexpr'. I understand the purpose and concept. But whenever I try to run it in a program there is always a bug even with the book example. Could someone please help me?
@kbw First I would like to thank you for replying so quickly, I really appreciate your help. & That's what I was thinking. This is a problem straight from the book. I like to go over the examples when I get down reading to grasp as much as I can. The two examples on how the book uses 'constexpr' I get a bug every time. here is the other example from the book where I get a bug using 'constexpr'. Like I said earlier I totally understand 'constexpr', but I'm confused on how to use it. Could you or anyone refer me to an example. I've looked around on the forum, but the examples I've ran across are a little too complex for what I know about c++ at the moment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
constexprdouble GetPi() { return 22.0 / 7; }
constexprdouble TwicePi() { return 2 * GetPi(); }
int main()
{
usingnamespace std;
constdouble pi = 22.0 / 7;
cout << "constant pi contains value " << pi << endl;
cout << "constexpr GetPi() returns value " << GetPi() << endl;
cout << "constexpr TwicePi() returns value " << TwicePi() << endl;
return 0;
}
constexpr (keyword) requires C++11.
If you are using a very old compiler, switch to a more recent one.
In addition, if it is the GNU or a GNU-compatible compiler, by default it compiles a home-grown Linux dialect based on of the superseded C++ standard. We would need to explicitly ask for standard C++ with -std=c++14 and -pedantic-errors (yes, say it twice; both options are required).
@TheldeasMan @kbw @JLBorges Sorry I confused you guise with the wrong word usage. I'm currently using Eclipse 3.8 on a Lunix OS, I thought it came with all the bells ans whistles as far as supporting c++11 & 14. Is there a way I can find what compiler I'm using through the IDE and also how do I go about updating it? Or better yet do you recommend another IDE for a beginner?