Can I overload operators +/-* for std::vector? Also how can I pass it into functions?
Code:
#include <iostream>
#include <iomanip>
#include <stdio.h> // standard input/output
#include <vector> // stl vector header
using namespace std; // saves us typing std:: before vector
int i;
int Particles = 5;
vector<double> addition(vector<double> X, vector<double> Y){
int Size = (int)X.size();
vector<double> Z;
for(i = 0; i < Size; i++){
Z.push_back( X[i] + Y[i]);
}
return Z;
}
int main()
{
// create an array of particle_field object pointers
double y;
vector<double> x_p, y_p, u_p, v_p, T_p;
// dynamically add some elements (use new operator)
for(i = 0; i < Particles; i++){
x_p.push_back(0);
y = 0.3/(Particles - 1)*i;
y_p.push_back(y);
u_p.push_back(0.6);
v_p.push_back(0);
}
T_p = 3*v_p + x_p;
T_p = addition(x_p, u_p);
}
Shuo