首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

类模板的有关问题啊答对的给分哦

2012-03-23 
类模板的问题啊,答对的给分哦!Higuys,Ihavethesecondquestionabouttemplate.Iencountereditduringmystudyi

类模板的问题啊,答对的给分哦!
Hi   guys,   I   have   the   second   question   about   template.   I   encountered   it   during   my   studying.

for   example,   I   have   a   template   class   both   in   .h   &   .cpp   files   as   follow:


1:     //   a.h
2:     template   <   class   T   >
3:     class   TTEST
4:     {
5:     public:
6:         struct   TS
7:         {
8:             int   i   ;
9:         }   ;
10:   public:
11:       TS*   test1()   ;
12:     }   ;

13:   //   a.cpp
14:   #include   "a.h "
15:   template   <   class   T   >
16:   TS*   TTEST   <   T   > ::test1()
17:   {
18:       return   NULL;
19:   }


But   I   got   a   compiler   error   at   line   16   while   building   it.   I   know   there   is   something   wrong   with   the   "   TS*   ",   but   I   don 't   know   how   to   fix   it.   Could   any   one   help   me   ?   thx   !

[解决办法]
1. 类模板的定义和实现都要放在.h中.
2.
template < class T >
TS* TTEST < T > ::test1()
{
return NULL;
}
=============>
template < class T >
typename TTEST <T> ::TS* TTEST < T > ::test1()
{
return NULL;
}

[解决办法]
lightnut() 是对的,不加typename 编译器不知道怎么解释*号,指针还是乘号编译器是不知道的。
[解决办法]
试试 lightnut() 的看看

热点排行