我正在尝试编译一个开源项目,但我从 g++ 中遇到了这个问题
错误:函数定义未声明参数
代码是这样的
#include <iostream>
namespace hi {
class hello {
public:
bool first { true };
};
}
int main(int argc, char *argv[])
{
hi::hello h
std::cout << "output: " << h.first << std::endl;
return 0;
}
使用
编译时会产生与开源项目的代码相同的编译问题g++ -O2 bools.cpp -o bools -std=c++0x
但是,如果我尝试使用相同的选项编译此代码,它会按预期编译和运行
#include <iostream>
int main(int argc, char *argv[])
{
bool value { true };
std::cout << "output: " << value << std::endl;
return 0;
}
我在 Ubuntu 64 位上使用 g++ 4.6.3。
感谢您的宝贵时间。
最佳答案
支持non-static data member initializers已在 gcc 4.7
中添加。您可以查看 gcc
支持哪些版本的 C++0x/C++11 功能列表 here 。此功能的行显示:
Non-static data member initializers | N2756 | GCC 4.7
这在 gcc 4.7
及更高版本中工作得很好,实时查看 here .
关于c++ - 扩展的初始值设定项列表被视为函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19073535/