How to access a std::vector from cling?

How do I access a std::vector in the main program from the cling interpreter?

For example if I declare a vector in my program:

std::vector int_vector;
// (add some values to the vector)

Now I run:

std::ostringstream nstr;
nstr << "for (int i = 0; i < 1000; i++)";
nstr << "   ref = int_vector[i] + 3 / 5;";
interp.process(nstr.str());

How would I reference int_vector in the string for the interpreter to access?

Hi jfi,

I don’t understand your question.

Axel

I edited my question to give a better idea of what I’m asking about.

Hi,
Thanks. See e.g. https://github.com/root-project/cling/blob/master/tools/demo/cling-demo.cpp#L61 for how to pass the pointer to some variable into the interpreter. Alternatively you could declare a function that modifies that vector, and declare that function to the interpreter - see the examples in the same file.

Cheers, Axel

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.