Template Inheritance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>

using namespace std;

template<typename T>class BaseClass
{
protected:
	int table;
};

template<typename T>class DerivedClass:public BaseClass<T>
{
public:
	void print();
};

template<typename T>void DerivedClass<T>::print()
{
	cout<<table<<endl;
}


Why am I not able to access the variable table? As far as I know we can access protected members of base class from the derived class.

It seems to be because of template lookup rules.

Adding

using BaseClass<T>::table;

solved this issue.

But I didn't get the actual reason why we need to write this? Can someone help me on this?
weird, as far as I knew it should work, in fact it worked for me on VC++
Topic archived. No new replies allowed.