C++ templates hides parent members

前端 未结 3 812
野性不改
野性不改 2021-02-10 03:55

Usually, when A is inheriting from B, all the members of A are automatically visible to B\'s functions, for example



        
3条回答
  •  我寻月下人不归
    2021-02-10 04:12

    You can also do

    class B : public A {
        int getA() {return this->a;}
    };
    

    The problem is that the member is in a base, which depends on a template parameter. Normal unqualified lookup is performed at the point of definition, not at the point of instantiation, and therefore it doesn't search dependent bases.

提交回复
热议问题