我已经定义在C++,其保持型的标量的阵列的类T为其中我想要定义像正弦,余弦等运营商为了限定的含义sin这个类的对象上施加我需要知道的意义sin上施加单标量类型T.这意味着我需要在类中使用适当的数学库(对应于标量类型T).这是现在的代码:
template<class T>
class MyType<T>
{
private:
std::vector<T> list;
// ...
template<class U> friend const UTP<U> sin(const UTP<U>& a);
template<class U> friend const UTP<U> cos(const UTP<U>& a);
template<class U> friend const UTP<U> tan(const UTP<U>& a);
//...
};
template<class T> const UTP<T> sin(const UTP<T>& a)
{
// use the sin(..) appropriate for type T here
// if T were double I want to use double std::sin(double)
// if T were BigNum …Run Code Online (Sandbox Code Playgroud)