Okay great! Almost everything works, I have no error in the formula, but something is blocking the main ():
Code:
#include <vector>
#include <iostream>
#include <cmath>
#define G 6.67e-11
#define N 2
using namespace std;
struct Coordinates
{
float x;
float y;
};
struct body{
float mass;
Coordinates position;
Coordinates velocity;
Coordinates acceleration;
};
Coordinates operator-( Coordinates a, Coordinates b)
{
Coordinates res;
res.x=a.x-b.x;
res.y=a.y-b.y;
return res;
}
float norm(Coordinates vector)
{
float n=sqrt(pow(vector.x, 2)+pow(vector.y, 2));
return n;
}
void calcul_acceleraton(vector<body> table_of_body)
{
Coordinates * table_of_acc=new Coordinates[N];
int i=0;
for(i; i<(N-1); i++)
{
table_of_acc[i].x=(table_of_body[i+1].mass)*( table_of_body[i+1].position.x );
table_of_acc[i].x=(table_of_body[i+1].mass)*( table_of_body[i+1].position.x - table_of_body[i].position.x )/abs(pow(norm(table_of_body[i].position-table_of_body[i+1].position), 3));
table_of_acc[i].y=(table_of_body[i+1].mass)*( table_of_body[i+1].position.y - table_of_body[i].position.y )/abs(pow(norm(table_of_body[i].position-table_of_body[i+1].position), 3));
cout <<table_of_acc[i].x<<endl;
}
table_of_acc[i].y*=G;
table_of_acc[i].x*=G;
}
int main()
{
vector<body*> list_body;
calcul_acceleraton(vector list_body); Missing template arguments before 'list_body'
return 0;
}
Missing template arguments before 'list_body' on the line calling the function calcul_acceleration
I have tried to:
Code:
list_body[1]. position.x = 1;
I put the following error:
error: request for member 'position' in 'list_body. std::vector<_Tp, _Alloc>::operator[] [with _Tp = body*, _Alloc = std::allocator<body*>](1ul)', which is of non-class type 'body*'
Bookmarks