Code that works in c++ doesn't work in ROOT? (using vectors)

Hi,

I have some simple code using vectors that works just fine when I compile it with gcc/g++, but gives me an error in ROOT…

#include
#include
using namespace std;

void vectorTest(){
double ** returnArray;
returnArray = new double*[3];
for(int i = 0; i < 3; i++){
returnArray[i] = new double[2];
}

vector<double> sendVector;
sendVector.push_back(returnArray);

}

In ROOT:
root [0] .L vectorTest.C
root [1] vectorTest()
Error: Can’t call vector::push_back(returnArray) in current scope FILE:vectorTest.C LINE:13
Possible candidates are…
filename line:size busy function type and name (in vector)
_vector.h 116:9 0 public: void push_back(double* *const& x);
Error: Symbol sendVector is not defined in current scope FILE:vectorTest.C LINE:13
Error: Failed to evaluate sendVector.push_back(returnArray)Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered ***

Meanwhile this exact same code (just with int main instead of void vectorTest and a return statement) compiles with g++ and runs without error.\

Thanks for your help,
Mikhail

Hi,

I am surprised that you manage to compile your code. I did:

root [0] .L vectorTest.C+ Info in <TUnixSystem>: creating shared library /var/tmp/./vectorTest_C.so/var/tmp/./vectorTest.C: In function 'void vectorTest()': /var/tmp/./vectorTest.C:13: error: no matching function for call to 'std::vector<double, std::allocator<double> >::push_back(double**&)'

Cheers,
Philippe

First of all:

Do you really mean vector of double, or, may be, it’s a forum’s usual problem with formatting???

If yes -
it’s an ill-formed program, none C++ compiler can compile it.
std::vector::push_back requires something, that can be initializer for const double &. Entity of type double ** cannot be such an initializer.