简体   繁体   English

统一初始化对ctor中的初始化父对象不起作用

[英]Uniform initialization doesn't work for initialization parent object in ctor

Suppose I have a struct: 假设我有一个结构:

struct A 
{
    int i;
};

I can init it as: 我可以将其初始化为:

A a{1};

Now I have a derived class: 现在我有一个派生类:

struct B : public A
{
     B(int _i) : A{_i} {};
};

But I have a compilation error in B struct ctor: 但我在B struct ctor中有一个编译错误:

error: no matching function for call to ‘A(<brace-enclosed initializer list>)’

Compiler is gcc-4.6 (SUSE Linux) 4.6.3 编译器是gcc-4.6(SUSE Linux)4.6.3

There is nothing wrong with your code; 你的代码没有错; it is simply that your compiler doesn't support all of the required C++11 features. 只是您的编译器不支持所有必需的C ++ 11功能。

Your constructor compiles fine with gcc 4.7.0. 你的构造函数使用gcc 4.7.0编译好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM