# Give argument to function added using TExec?

**URL:** <https://root-forum.cern.ch/t/give-argument-to-function-added-using-texec/55777>\
**Category:** Newbie\
**Created:** [July 20, 2023, 4:44pm UTC](https://root-forum.cern.ch/t/give-argument-to-function-added-using-texec/55777 "2023-07-20T16:44:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1vy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/1/a3d4f5/32.png) [@1vy](https://root-forum.cern.ch/u/1vy)\
**Post date:** [July 20, 2023, 4:44pm UTC](https://root-forum.cern.ch/t/give-argument-to-function-added-using-texec/55777/1 "2023-07-20T16:44:36Z")

</div>

Hi, I know this is probably a really basic question answered somewhere in the documentation, but I am really new to programming so I struggle to find the answer! 🙂

I want to do something like this where the argument is just a vector:

```auto
TExec* ex = new TExec("ex", "function(argument);");

```

and my function would look something like:

```auto
void function(std::vector<std::string> argument)
{...

```

This is just to draw points of different colors based on the entries of a string vector. How do I pass these arguments along? Thank you.

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [July 21, 2023, 10:49am UTC](https://root-forum.cern.ch/t/give-argument-to-function-added-using-texec/55777/2 "2023-07-21T10:49:11Z")

</div>

Hi and welcome on the forum,

If you will define function so:

```auto
void func1(const std::vector<std::string> &argument) {
}

```

Then you can invoke it:

```auto
TExec* ex = new TExec("ex", "func1( { \"arg1\", \"arg2\", \"arg3\" } );");

```

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![1vy](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/1/a3d4f5/32.png) [@1vy](https://root-forum.cern.ch/u/1vy)\
**Post date:** [July 22, 2023, 8:33pm UTC](https://root-forum.cern.ch/t/give-argument-to-function-added-using-texec/55777/3 "2023-07-22T20:33:26Z")

</div>

Thank you for your help! I think this is barking up the right tree, but I am still having some issues that I am not sure how to resolve. Here is how I used TExec:

```auto
TExec* exLV60 = new TExec("exLV60", "DrawCol(\"LV60_statusVector\");");

```

LV60\_statusVector has already been initialized as `std::vector<std::string>.`

This is how I have defined my function:

```auto
void DrawCol(std::vector<std::string> &argument) 

```

I am not sure why I am getting the following warnings:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/0/d/0d6bbf28655bc088b29261b04f33be21a4729423.png)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 27, 2023, 10:45am UTC](https://root-forum.cern.ch/t/give-argument-to-function-added-using-texec/55777/4 "2023-07-27T10:45:52Z")

</div>

Welcome to the ROOT forum

Can you provide a small macro reproducing your problem ?

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [August 7, 2023, 9:21am UTC](https://root-forum.cern.ch/t/give-argument-to-function-added-using-texec/55777/5 "2023-08-07T09:21:42Z")

</div>

Hi,

> [@1vy](#):
>
> LV60\_statusVector has already been initialized as `std::vector<std::string>.`

Only global variable can be used at such call.  
`LV60_statusVector` must be declared outside of function scope.  
And you should remove quotes around variable name.  
Macro `test.C` should look like:

```auto
std::vector<std::string> LV60_statusVector = { "one", "two", "three" };

void DrawCol(const std::vector<std::string> &argument) {
}

void test() {
   ...
   TExec* exLV60 = new TExec("exLV60", "DrawCol(LV60_statusVector);");
   ...
}

```

Regards,  
Sergey
