I have created a TVector3 array, and I want to use it as a function parameter like below. But I find I can only get the first TVector, position[0][0]. How to solve this?
this will get you started.
With ROOT6 and in general starting from C++11 manipulation and spelling of types is easy. here we do not even write the name of the type in the signature!
#include "TVector3.h"
#include <iostream>
#include <typeinfo>
using namespace std;
TVector3 position[14][22];
void CalcCoG(decltype(position)& position)
{
for (short i = 0; i < 14; i++) {
for (short j = 0; j < 22; j++) {
cout << "position" << "[" << i << "]" << "[" << j << "]" << " x:" << position[i][j].X() << endl;
}
}
}
int main()
{
for (short i = 0; i < 14; i++) {
for (short j = 0; j < 22; j++) {
position[i][j].SetX(i*j);
}
}
CalcCoG(position);
cout << "The type name is " << typeid(position).name() << endl;
}
This would be the C++98 version.
#include "TVector3.h"
#include <iostream>
#include <typeinfo>
using namespace std;
TVector3 position[14][22];
void CalcCoG(TVector3 (*position)[22])
{
for (short i = 0; i < 14; i++) {
for (short j = 0; j < 22; j++) {
cout << "position" << "[" << i << "]" << "[" << j << "]" << " x:" << position[i][j].X() << endl;
}
}
}
int main()
{
for (short i = 0; i < 14; i++) {
for (short j = 0; j < 22; j++) {
position[i][j].SetX(i*j);
}
}
CalcCoG(position);
cout << "The type name is " << typeid(position).name() << endl;
}