Hi I am having some doubts regrading templates. Please look into follwoing snippet.
template<class T_Type1>
class CSmall
{
public:
class Const_Itr
{
T_Type1 Outer_A;
};
private:
T_Type1 Inner_A;
};
template<class T_Type>
class CBig
{
public:
CSmall<T_Type>::Const_Itr*开发者_运维问答 obj1;//ERROR C2143: syntax error : missing ';' before '*'
typename CSmall<T_Type>::Const_Itr* obj2;// NO error after using 'typename' keyword
}; // CIPPortExpectationHandler
void main()
{
CSmall<int>::Const_Itr* obj3;// NO error even if 'typename' keyword in NOT used.
}
can somebody explain me following
- Why declaration of 'obj1' is giving error.
- How typename solves this problem while declaring 'obj2'. what info is gained by compiler
- Why declaration of 'obj3' inside main() works without typename.
Note: snippet is complied on VC++ 8.0
Thanks in Advance
See this FAQ: What is the template typename
keyword used for?
compiler has no clue if CSmall<T_Type>::Const_Itr
is a type or a variable. So you should provide some help. While CSmall<int>::Const_Itr
is obviously a type.
精彩评论