x-x*_*x-x 47 c++ gcc g++ uniform-initialization c++11
注意派生使用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;
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
更新1:它也编译没有警告与clang ++ - 3.1
Update 2:看起来像编译器错误肯定.它显然已在GCC 4.7.3中修复.
| 归档时间: |
|
| 查看次数: |
1916 次 |
| 最近记录: |