双模板<>语句

scd*_*dmb 19 c++

有这样的功能定义:

template<>
template<>
void object::test<1>()
{
}
Run Code Online (Sandbox Code Playgroud)

什么意思是有双模板<>?

编辑:

我提取了对此示例有效的代码:

#include <iostream>

template <class U>
class A {

    template <int n>
    void test() {

    }
};

template <class T>
class B {
public:
    typedef A<T> object;
};

typedef B<int>::object object;

template<>
template<>
void object::test < 1 > () {
}

int main() {
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

此代码在g ++下编译.

资料来源:TUT测试框架

Ale*_*tov 18

例如,

template<class T = int> // Default T is int
class object<T> {
   template<int R> void test ();
};
Run Code Online (Sandbox Code Playgroud)

你的代码:

template<> // T is fixed
template<> // R is fixed
void object<>::test<1>() // T is default int, R is 1
{
}
Run Code Online (Sandbox Code Playgroud)

相当于:

template<> // T is fixed
template<> // R is fixed
void object<int>::test<1>() // T is int, R is 1
{ 
} 
Run Code Online (Sandbox Code Playgroud)