Why do I have to access template base class members through the this pointer?

后端 未结 3 2355
无人及你
无人及你 2020-11-21 04:49

If the classes below were not templates I could simply have x in the derived class. However, with the code below, I have to use this

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 05:18

    The x is hidden during the inheritance. You can unhide via:

    template 
    class derived : public base {
    
    public:
        using base::x;             // added "using" statement
        int f() { return x; }
    };
    

提交回复
热议问题