In "The C++ Standard Library" Josuttis gives this example(on p.11):
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:template <class T> class MyClass{ typename T::SubType * ptr; ... };
He continues his explanation by saying: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; }
I don't understand why he says that SubType is a value of type T? It seems to me that when you writeThus,
T::SubType * ptr;
would be a multiplication of value SubType of type T with ptr.
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:
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.Code:cout<<Box::SubType<<endl;



LinkBack URL
About LinkBacks


