注意,派生使用C++11统一初始化语法来调用基类构造函数。
class base
{
protected:
base()
{}
};
class derived : public base
{
public:
derived()
: base{} // <-- Note the c++11 curly brace syntax
// using uniform initialization. Change the
// braces to () and it works.
{}
};
int main()
{
derived d1;
return 0;
}g++4.6编译这一点,但是g++4.7没有:
$ g++-4.7 -std=c++11 -Wall -Wextra -pedantic curly.cpp -o curly
curly.cpp: In constructor ‘derived::derived()’:
curly.cpp:4:13: error: ‘base::base()’ is protected
curly.cpp:19:24: error: within this context到底怎么回事?
更新1:它也使用clang++-3.1编译而没有警告
更新2:看上去肯定是编译器的错误。 --显然是在GCC 4.7.3中修正的。
发布于 2012-10-17 22:52:10
保罗·卡里尼( Paolo Carlini ),GCC/libstdc++贡献者,确认是错误/回归。
发布于 2012-09-14 17:18:33
这可能是因为在4.7版中添加了C11显式覆盖控件。
发布于 2012-09-18 16:46:45
用icpc编译它(用11.1版本-> 12.1测试英特尔编译器)提供:
-bash-3.2$ icpc -std=c++0x test.c
test.c(15): error: expected a declaration
{}
^
test.c(12): error: expected a "("
: base{} // <-- Note the c++11 curly brace syntax
^
compilation aborted for test.c (code 2)编辑:但话说回来,c++11还没有在icpc或http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler/中完全实现
和g++ status.html一样
这显然表明它仍然是实验性的,所以一个bug是很有可能的。
https://stackoverflow.com/questions/12313292
复制相似问题