我有一些使用某些c++11功能的第三方工具,我需要在gcc 4.4下编译它.由于我对c++11新功能一点也不熟悉,但我认为在谷歌搜索结果毫无结果之后我会寻求帮助.
我启用了c++0x开关,但它没有帮助:
for (auto const& fixup : self->m_Fixups)
Run Code Online (Sandbox Code Playgroud)
产生的错误是:
error: expected initializer before ':' token
Run Code Online (Sandbox Code Playgroud)
还有哪些其他范围循环语法与C++11范围循环等效地GCC 4.4支持?
代码是一个基于范围的for循环,在C++ 11中确实是新的.与C++ 11中的其他一些功能不同,它没有在GCC 4.4中实现.试试这个:
for( auto it = self->m_Fixups.begin(); it != self->m_Fixups.end(); ++it )
{
const auto& fixup = *it;
// the rest of the code...
}
Run Code Online (Sandbox Code Playgroud)
以上使用了一些 C++ 11功能,这些功能应该在GCC 4.4中提供.
正如Ben Voigt所指出的:如果你需要提高代码效率,你可能也会使用这个稍微简洁的版本:
for( auto it = self->m_Fixups.begin(), end = self->m_Fixups.end(); it != end; ++it )
{
const auto& fixup = *it;
// the rest of the code...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
968 次 |
| 最近记录: |