さっそく質問に入ります。
テンプレートの専門化があります。
class TestClass
{
public:
template<typename T>
static T fn(const T& a);
}
// OK
template<typename T>
T TestClass::fn(const T& a)
{
// ... magic for any type here ...
}
// OK
template<>
int TestClass::fn(const int& a)
{
// ... magic for int type here ...
}
すべて大丈夫です。しかし、関数にパラメーター パックを追加したい場合はどうすればよいでしょうか。
class TestClass
{
public:
template<typename T, typename... Args>
static T fn(const T& a, Args&& ...b);
}
// OK
template<typename T, typename... Args>
T TestClass::fn(const T& a, Args&& ...b)
{
// ... magic for any type here ...
}
// Error
template<typename... Args>
int TestClass::fn(const int& a, Args&& ...b)
{
// ... magic for int type here ...
}
Visual Studio でエラー E0147 が発生します。クラスに新しい関数を追加せずにこれを行うにはどうすればよいですか?
よろしくお願いします。
良い1日を!