小编use*_*246的帖子

C++中向量的交叉积

作为我正在编写的程序的一部分,我需要找到双向量和复数双向量的交叉乘积.我写了一个我认为应该这样做的函数,但是当我调用它时,我收到以下错误:

error: no matching function for call to ‘CrossProduct1D(std::vector< double, std::allocator<double> >&, std::vector<std::complex<double>, std::allocator<std::complex<double> > >&)’
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <math.h>
#include <complex>
using namespace std;

//1D cross product
template <typename T>
vector<T> CrossProduct1D(vector<T> const &a, vector<T> const &b)
{
  vector<T> r (a.size());  
  r[0] = a[1]*b[2]-a[2]*b[1];
  r[1] = a[2]*b[0]-a[0]*b[2];
  r[2] = a[0]*b[1]-a[1]*b[0];
  return r;
}

//::::::::importing data from text::::::::::
  vector<string> ezivec;
  ezivec.reserve(4000);

  string ezidat("ez.i.txt");

  ifstream ezifile;
  ezifile.open(ezidat.c_str());

  if(!ezifile.is_open())
    {
      cerr<<"Error opening file …
Run Code Online (Sandbox Code Playgroud)

c++ function cross-product

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

标签 统计

c++ ×1

cross-product ×1

function ×1