开发者

How do I write this template specification when I'm outside the 'class' definition

This is something that I never ran into before. Say I have a class that looks like this:

template <class T1>
class A
{
   void normal_function();

   template <class T2>
   void templated_function(T2);
}

Because of coding standards, I'm not allowed to put the body of templated_function inside of the class definitions, i have to have it below (b开发者_开发技巧ut still in the .h file).

So I have something like this

template <class T1>
void A<T1>::normal_function()
{
  ...
}

But how do I write the template specification for templated_function when it's outside of the class definition? I tried this, but it didn't seem right to me, and I wasn't surprised when it didn't compile.

template <class T1, class T2>
void A<T1>::templated_function<T2>(T2 t)
{
  ...
}


This works with g++:

template<class T1> template<class T2>
void A<T1>::templated_function(T2 t)
{
   ...
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜