C ++ exception and ld character warning

I play with throwing exceptions in C ++ and I have the following test code:

#include <iostream> #include <stdexcept> #include <new> using namespace std; class Myerror : public runtime_error { private: string errmsg; public: Myerror(const string &message): runtime_error(message) { } }; int main(int argc, char *argv[]) { throw Myerror("wassup?"); } 

I compile this with

icpc -std = C ++ 11 -O3 -m64

When compiling, I get this ld warning:

ld: warning: direct access in _main to the global weak character __ZN7MyerrorD1Ev means that the weak character cannot be redefined at run time. This is probably due to the fact that different translation units are compiled with different visibility settings.

I do not get this warning if I use g ++ instead of icpc.

I could not understand what this means and what causes this warning. The code works as expected, however I would like to undesratand what happens.

+6
source share
1 answer

Try the following:

 #include <iostream> #include <stdexcept> #include <new> using namespace std; class Myerror : public runtime_error { public: Myerror(const string &message) throw(): runtime_error(message) { } virtual ~Myerror() throw() {} }; int main(int argc, char *argv[]) { throw Myerror("wassup?"); } 

Why do you need an unused errmsg string?

+1
source

All Articles