开发者

C2143 with nested template classes

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

  1. Why declaration of 'obj1' is giving error.
  2. How typename solves this problem while declaring 'obj2'. what info is gained by compiler
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜