In "The C++ Standard Library" Josuttis gives this example(on p.11):
Code:
template <class T>
class MyClass{
typename T::SubType * ptr;
...
};
He says that without the typename keyword, SubType would be considered a static member. Ok, that seems to make some sense because a static member can be referenced like this:
Code:
#include <iostream> //cout
using namespace std;
class Box //T = Box
{
public:
static int SubType;
};
//intialize static data member:
int Box::SubType = 4;
int main()
{
cout<<Box::SubType<<endl;
return 0;
}
He continues his explanation by saying:
Thus,
T::SubType * ptr;
would be a multiplication of value SubType of type T with ptr.
I don't understand why he says that SubType is a value of type T? It seems to me that when you write
T::SubType
that only says that SubType is a static member of T, and it doesn't speak to the type of SubType at all. In my example above, the statement:
Code:
cout<<Box::SubType<<endl;
does not say that SubType is of type Box. It just says to go look in the Box class for a static member variable called SubType. The type of SubType is actually int.