相关疑难解决方法(0)

C++ - 重载模板化类方法,并对该方法进行部分说明

在堆栈溢出上已经有一些类似于此的问题,但似乎没有什么能直接回答我的问题.如果我重新发布,我会道歉.

我想重载一些模板化类的方法(带有2个模板参数),并对这些方法进行部分模板特化.我无法弄清楚正确的语法,并开始认为这是不可能的.我以为我会在这里发帖,看看能不能得到确认.

要遵循的示例代码:

template <typename T, typename U>
class Test
{
public:
    void Set( T t, U u ); 

    T m_T;
    U m_U;
};

// Fully templated method that should be used most of the time
template <typename T, typename U>
inline void Test<T,U>::Set( T t, U u )
{
    m_T=t;
    m_U=u;
}

// Partial specialisation that should only be used when U is a float.
// This generates compile errors
template <typename T>
inline void Test<T,float>::Set( T t, float …
Run Code Online (Sandbox Code Playgroud)

c++ templates overloading partial-specialization

0
推荐指数
1
解决办法
2642
查看次数