Can't access members of a Template base class within a derived template class

后端 未结 4 1897
广开言路
广开言路 2020-12-22 03:45

I have a template base class.Lets say.

template
class Base 
{
  private:
   int member1;
   char member2;
   ....
};

I de

4条回答
  •  自闭症患者
    2020-12-22 04:28

    I think two changes needed to solve the issue:

    1. In base class, define the member as "protected" instead of "private" to be accessible in the derived class.

    2. In derived class, add the base class name ahead of the protected member. In this case, it should look like "Base::member1".

    Using C++17 standard in my case, the issue was resolved. Hope this is helpful. Thanks to Kerrek SB for the info.

提交回复
热议问题