我使用C ++的业余状态可能会使我从显而易见的事业中眩目,但我试图为一个交叉产品编写一段简单的代码。我想让它可供以后使用,所以我试图通过头文件将向量传递给单独的.cpp。这就是我现在所拥有的:
.cpp for Main
#include <iostream>
#include <vector>
// Custom Functions
#include "G:\Visual Studio\source\repos\Functions\Functions\Functions.h"
int main() {
std::vector<double> r_0(3), v_0(3), h(3);
double X_0[1][6] = {
{ 1.0, 0.0, 0.0, 1.0, 1.0, 0.0 }
};
for (int j = 0; j < 3; j++) {
r_0[j] = X_0[0][j];
v_0[j] = X_0[0][j + 3];
};
XP_Function h_func;
h = h_func.X_Product(r_0, v_0);
std::cout << h[0] << " " << h[1] << " " << h[2] << std::endl;
return 0;
}
标题.h
#pragma once
#include <iostream>
#include <vector>
class XP_Function {
public:
std::vector<double> X_Product(std::vector<double> u, std::vector<double> v);
private:
std::vector<double> XP;
};
.cpp for function
#include <iostream>
#include <vector>
#include <cmath>
#include "Functions.h"
std::vector<double> XP_Function::X_Product(std::vector<double> u, std::vector<double> v) {
std::vector<double> XP(3);
XP[0] = u[1] * v[2] - u[2] * v[1];
XP[1] = u[2] * v[0] - u[0] * v[2];
XP[2] = u[0] * v[1] - u[1] * v[0];
return XP;
}
这些是我得到的错误:
1>Test.obj : error LNK2019: unresolved external symbol "public: class std::vector<double,class std::allocator<double> > __thiscall XP_Function::X_Product(class std::vector<double,class std::allocator<double> >,class std::vector<double,class std::allocator<double> >)" (?X_Product@XP_Function@@QAE?AV?$vector@NV?$allocator@N@std@@@std@@V23@0@Z) referenced in function _main
1>G:\Visual Studio\source\repos\Test\Debug\Test.exe : fatal error LNK1120: 1 unresolved externals
我很欣赏任何见解。如果只是一个简单的错误,请道歉。我真的刚刚开始一周前,一年前只有一门课程。