C++: Why does my DerivedClass's constructor not have access to the BaseClass's protected field?

前端 未结 6 995
执笔经年
执笔经年 2020-12-14 06:14

I have a constructor attempting to initialize a field in a base class. The compiler complains. The field is protected, so derived classes should have access.



        
6条回答
  •  情话喂你
    2020-12-14 06:44

    Initializer lists can only be used to initialize fields which are owned by the type in question. It is not legal to initialize base class fields in an initializer lists which is why you receive this error. The field is otherwise accessible within DerivedClass

提交回复
热议问题