【发布时间】:2014-03-21 12:11:05
【问题描述】:
我遇到了跨平台编译的问题。 下面的代码可以在 Win、Mac 和 Linux 上编译(程序是基于 Qt 的),但是为了让它在 Mac 和 Linux 上编译,我必须定义 if/else。
Windows 编译器 (VS2010) 找到定义,但 Mac (gcc4.2) 和 Linux (Ubuntu12LTS) 找不到...
有什么想法吗?也许我错过了一些技术术语来搜索这个? 我希望能够使用“table->setMark(i,MyObj());”适用于所有系统,因为它似乎没有任何特定于平台的代码。
///// .h
void setMark(int row, MyObj& mark)
{ value(row).setMark(mark); }
const MyObj& getMark(int row) const
{ return value(row).getMark(); }
/////
///// .cpp
MyObj obj;
bool ret = false, ifhandled = false;
m_root_command.evaluate(obj,ret,ifhandled);
if (m_marked) {
Table *table = m_thisobj.getTable();
for (int i = 0; i < table->getRowCount(); i++) {
#if defined(_WIN32)
// this works in windows, but fails to compile
// on other platforms with error below
table->setMark(i,MyObj());
#else
// I want to get rid of this workaround
// and use the above code for all platforms
MyObj objTmp = MyObj();
table->setMark(i,objTmp);
#endif
}
m_marked = false;
}
/////
///// Error
program.cpp: In member function 'MyObj Program::evaluate()':
program.cpp:264:36: error: no matching function for call to 'Table::setMark(int&, MyObj)'
program.cpp:264:36: note: candidate is:
table.h:326:9: note: void Table::setMark(int, MyObj&)
table.h:326:9: note: no known conversion for argument 2 from 'MyObj' to 'MyObj&'
make: *** [program.o] Error 1
/////
【问题讨论】:
标签: c++ linux windows macos gcc