Accessing variables from base template class in derived class constructor in C++

后端 未结 2 885
一整个雨季
一整个雨季 2021-01-22 21:32

Let\'s look at this simple code sample including a base class and a class derived from Base, which needs the address of a base class member in its constructor.

#         


        
2条回答
  •  伪装坚强ぢ
    2021-01-22 21:44

    In the second case, the Base is a template and someone might add specializations for the template, all with different member variables. The compiler cannot know until it sees what T is.

    There might also be a global arr that could fit. You can help the compiler by using this->arr[0] to indicate that it always is a member variable.

提交回复
热议问题