c++ - 抛出和共享对象的可见性

标签 c++ object visibility shared throw

我正在将代码从 Windows 移植到 CentOS,但我遇到了一个我以前从未见过的问题。

鉴于该函数声明(还有更多):

byte getValueInt8() const throw(.../*Exception*/);

我收到这个错误:

error: expected type-specifier before ‘...’ token unsigned short getValueInt8() const throw(.../*Exception*/);

当然,我查过互联网,发现这是共享对象中的可见性问题。

本站https://gcc.gnu.org/wiki/Visibility对此进行了解释,但我在阅读时已经这样做了。

我的定义是:

#if defined(_MSC_VER)
#include <winsock2.h>
   #ifdef MFTINTERFACE_EXPORTS
      #define EXPORT_IMPORT __declspec(dllexport)
   #else
      #define EXPORT_IMPORT __declspec(dllimport)
   #endif
#elif defined(_GCC)
   #include <arpa/inet.h>
   #include "CmnSocketsDef.h"
   #include "CmnDefs.h"
   #define EXPORT_IMPORT __attribute__((visibility("default")))   
#else
   #define EXPORT_IMPORT
   #define IMPORT
   #pragma warning Unknown dynamic link import/EXPORT_IMPORT semantics.
#endif

当然,所有的 EXPORT_IMPORT 都在我的代码中设置好了。

修改前的代码在Windows下编译。

最佳答案

throw(...) 作为异常规范是不合法的 c++。

我只能假设您遇到过 Microsoft abomination 扩展。

您需要将其删除。在任何情况下,唯一在现实中有意义的异常说明符是 nothrow(如果您使用的是古老的编译器,则为 throw())。

的确,这是确凿的证据:

https://msdn.microsoft.com/en-us/library/wfa0edys.aspx

弃用建议:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3051.html

关于c++ - 抛出和共享对象的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37212298/

相关文章:

c++ - 在不使用 abs 函数或 if 语句的情况下获取绝对值

c++ - getline C++ 的奇怪行为

c++ - 逐行计算文件 : EOF repeating the last number (can't use breaks)

linux - 找出函数符号在目标文件 (.o) 中的可见性

c++ - Oracle Solaris Studio 内存泄漏与 cout

javascript - 尝试理解 javascript 中的对象和方法创建

C++ 错误 : passing ‘const std::vector<Node>’ as ‘this’ argument discards qualifiers [-fpermissive]

c++ - 如果是一个类的私有(private)数据成员并且我们创建该类的两个对象,那么指向 int 数据类型的指针是什么?

postgresql - 由于 "malformed record literal"无法插入记录

c# - WPF:绑定(bind)到 MainWindow 属性