我想到的应用程序类似于Vector<size>类,我希望在其中声明
CrossProduct(const Vector<size>& other)
Run Code Online (Sandbox Code Playgroud)
仅适用于尺寸为3的情况.我知道有很多方法可以解决它...
有没有办法正确地声明特定实例化的成员函数?
这是一种方法:
template <class Type, size_t Size>
struct EnableCrossProduct
{
};
template <class Type>
struct EnableCrossProduct<Type, 3>
{
void CrossProduct(const Type & other){}
};
template <size_t Size>
struct Vector : public EnableCrossProduct<Vector<Size>, Size>
{
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
120 次 |
| 最近记录: |