| 25 | |
| 26 | template <typename T> |
| 27 | void Derived<T>::derivedFun() |
| 28 | { |
| 29 | // These two lines should give compiler errors. |
| 30 | // Uncomment the using declarations in the Derived<> template |
| 31 | // to make them work. Alternative solutions are illustrated below. |
| 32 | baseFun(); |
| 33 | std::cout << m_base_var << std::endl; |
| 34 | |
| 35 | // Option 1: add this-> |
| 36 | this->baseFun(); |
| 37 | std::cout << this->m_base_var << std::endl; |
| 38 | |
| 39 | // Option 2: add Base<T>:: |
| 40 | Base<T>::baseFun(); |
| 41 | std::cout << Base<T>::m_base_var << std::endl; |
| 42 | } |
| 43 | |
| 44 | int main() |
| 45 | { |