0

take a look at this code:

template <class T>
class C {
public:

	class A {

	protected:
		int x;
	};

	class B: public A {
	protected:
		void write() {
			cout << x << endl;
		}
	};

};

when I try to compile with g++ i get:
test.cpp: In member function ‘void C<T>::B::write()’:
test.cpp:18: error: ‘x’ was not declared in this scope

If I remove the template argument of class C all workes fine ( of course )
Does anyone have an ideea of what is going on?

thx in advance

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by kux
0

Well where are you exactly using template functionalities in this code segment ??? I don't see its usage anywhere in the code given by you.

0

Well where are you exactly using template functionalities in this code segment ??? I don't see its usage anywhere in the code given by you.

It's just a sample I made to hilight the compile error. I might use the template parameter on other methods I didn't post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.