我正在努力将一些 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++ 知识以及异常是如何工作的。