我正在努力将一些C ++代码从Windows改为Linux,以便在Matlab中编译为mex。该程序旨在通过虚拟串行端口连接数据手套。我之前从未使用过C ++,所以解决这个问题的方法很简单。在一个更大的文件中,我遇到了由以下try / catch引起的问题:
try
{
// You can tell which com port to use by checking windows settings under hardware
glove = new CyberGlove(portName, (int) *baudRate); // baudrate 115200
/* Return CyberGlove object */
mxArray* result = (mxArray*) mxMalloc(sizeof(CyberGlove));
*reinterpret_cast<CyberGlove*>(result) = *glove;
plhs[0] = result;
}
catch(std::runtime_error err)
{
std::cout << "Error: " << err.what() << std::endl;
}
delete glove;
当我尝试在Matlab中编译它时,我收到以下错误:
InitCyberGlove.cpp: In function ‘void mexFunction(int, mxArray**, int, const mxArray**)’:
InitCyberGlove.cpp:43:11: error: expected type-specifier
InitCyberGlove.cpp:43:30: error: expected unqualified-id before ‘err’
InitCyberGlove.cpp:43:30: error: expected ‘)’ before ‘err’
InitCyberGlove.cpp:43:30: error: expected ‘{’ before ‘err’
InitCyberGlove.cpp:43:30: error: ‘err’ was not declared in this scope
InitCyberGlove.cpp:43:33: error: expected ‘;’ before ‘)’ token
我认为这与CyberGlove的内容没有特别关系,因为我普遍缺乏对C ++的了解以及异常如何运作。
答案 0 :(得分:2)
您需要#include <stdexcept>
宣布std::runtime_error
。