Search ProofOfProgress Blog

Sunday, March 15, 2015

error: ‘logic_error’ is not a member of ‘std’

Closest matching post isn't very close:
https://groups.google.com/forum/#!topic/quickfast_users/vXq5xZH7rqo

/source.cpp: In function ‘int main(int, char**)’:
/source.cpp:52:23: error: ‘logic_error’ is not a member of ‘std’
                 throw std::logic_error("woah buddy");


Don't understand... Because I have the same line of code working in some other code of mine.
And all the examples say to write it the way I have:

throw std::logic_error("woah buddy");

Quoting:
http://stackoverflow.com/questions/2924058/confused-about-stdruntime-error-vs-stdlogic-error
"std::logic_error is thrown by a user C++ program logic intentionally. Predicted by a user program."

https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.5/a00537.html
huntch that maybe #using <stdexcept> might help?

YES.
If you are not using namespace std, then you must
put #using in the top of your c++ file to get std::logic_error to work.

Which is weird to me. Because I included "std::" so shouldn't it work without any declarations?
I don't know what I am doing.

But. Trying to code without the "using namespace std" to avoid name collisions and other weird

errors that I hear can happen by importing a whole bunch of things you do not need into the global namespace.

2 comments:

  1. The 'const char *' form is only supported by C++11 and later; for earlier versions, you have to use the 'const std::string' form.

    ReplyDelete
  2. The 'const char *' form is only supported by C++11 and later; for earlier versions, you have to use the 'const std::string' form.

    ReplyDelete