Access protected member of a class in a derived class

后端 未结 2 1156
我在风中等你
我在风中等你 2020-12-11 03:36

i have an old codebase here, where they used protected member variables. Whether or not this is a good idea can be discussed. However, the code must have compiled fine with

2条回答
  •  眼角桃花
    2020-12-11 04:01

    When you're defining the derived template, the compiler only knows the base template class' name but not its details, so compiler doesn't know the derived class has an inherited member. In order to tell the compiler of the member's existence, use this->, just like you did.

    Actually, it is a duplicate of this question.

提交回复
热议问题