Lod*_*dle 0 c++ linux variadic-functions
对于我的异常类,我有一个具有多个参数(...)的构造函数,它在windows下工作正常,但是在linux下它编译得很好但是拒绝链接到它.
为什么这不能在linux下运行?
这是一个例子:
class gcException
{
public:
gcException()
{
//code here
}
gcException(uint32 errId, const char* format = NULL, ...)
{
//code here
}
}
enum
{
ERR_BADCURLHANDLE,
};
Run Code Online (Sandbox Code Playgroud)
.
编辑
所以,当我这样称呼时:
if(!m_pCurlHandle)
throw gcException(ERR_BADCURLHANDLE);
Run Code Online (Sandbox Code Playgroud)
我得到这个编译错误:
error: no matching function for call to ‘gcException::gcException(gcException)’
candidates are: gcException::gcException(const gcException*)
gcException::gcException(gcException*)
gcException::gcException(gcException&)
Run Code Online (Sandbox Code Playgroud)
问题是你的拷贝构造函数不接受你给throw的临时值.这是一个临时的,因此是一个左值.引用到非对象,即gcException&不能绑定它.阅读这里的细节.
正如对该答案的评论所暗示的那样,微软编译器有一个错误,它使绑定引用指向非const对象接受rvalues.您应该将copy-constructor更改为:
gcException(gcException const& other) {
// ...
}
Run Code Online (Sandbox Code Playgroud)
使它工作.它说这个bug是在Visual C++ 2005中修复的.所以你会遇到与该版本相同的问题.所以最好立即修复这个问题.