Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 指定一些模板参数_C++_Templates_Vector - Fatal编程技术网

C++ 指定一些模板参数

C++ 指定一些模板参数,c++,templates,vector,C++,Templates,Vector,我想写一个自己的向量类和一个计算叉积的函数 我的向量类有 template<class T, int dim, bool isRowVector> 模板 T是条目的类型,dim是维度,isRowVector指定向量是行向量还是列向量 我重载了向量的一些操作符,尤其是操作符中的 template <class T, int dim, bool isRowVec> std::ostream& operator<<(std::ostream& o

我想写一个自己的向量类和一个计算叉积的函数

我的向量类有

template<class T, int dim, bool isRowVector>
模板
T是条目的类型,dim是维度,isRowVector指定向量是行向量还是列向量

我重载了向量的一些操作符,尤其是
操作符中的
template <class T, int dim, bool isRowVec>
std::ostream& operator<<(std::ostream& os, Vector<T, dim, isRowVec>& vec) // <<
{
    os << "[" << vec[0];

    for(typename std::vector<T>::iterator it = vec.begin()+1; it != vec.end(); it++) {
        os << "," << *it;
    }

    os << "]";

    if(!isRowVec) { os << "^T"; }

    return os;
}
template <class T, bool isRowVec>
Vector<T, 3, isRowVec> crossProduct (Vector<T, 3, isRowVec> a, Vector<T, 3, isRowVec> b) {
    T arr[3] = { a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0] };
    Vector<T, 3, isRowVec> newVec(arr);
    return newVec;
}
Vector<float,3,true> a = crossProduct(f,g);
Vector<float,3,true>
std::cout << crossProduct(f, g) << std::endl;
error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'Vector<float, 3, true>')
  std::cout << crossProduct(f, g) << std::endl;
            ^
std::cout << crossProduct(f, g) << std::endl;
             |
             |
             +------Creates a temporary object (rvalue)
template <class T, int dim, bool isRowVec>
std::ostream& operator<<(std::ostream& os, const Vector<T, dim, isRowVec>& vec) 
//                                         ~~~~~
{
   // ....
}