C++异常和ld符号警告

dee*_*pak 6 c++ exception ld icc

我正在玩在C++中创建异常,我有以下测试代码:

#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?");
}
Run Code Online (Sandbox Code Playgroud)

我正在编译这个:

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

编译后,我得到这个ld警告:

ld:警告:在_main中直接访问全局弱符号__ZN7MyerrorD1Ev表示在运行时无法覆盖弱符号.这可能是由使用不同可见性设置编译的不同翻译单元引起的.

如果我使用g ++而不是icpc,我不会收到此警告.

我无法理解这意味着什么,以及导致此警告产生的原因.代码按预期运行,但是我想不想发生什么.

小智 1

请尝试以下操作:

#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?");
}
Run Code Online (Sandbox Code Playgroud)

为什么需要未使用的字符串 errmsg?