# Vector declaration error

**URL:** <https://root-forum.cern.ch/t/vector-declaration-error/43230>\
**Category:** Newbie\
**Created:** [January 23, 2021, 9:46pm UTC](https://root-forum.cern.ch/t/vector-declaration-error/43230 "2021-01-23T21:46:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmg](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e68b1a/32.png) [@jmg](https://root-forum.cern.ch/u/jmg)\
**Post date:** [January 23, 2021, 9:46pm UTC](https://root-forum.cern.ch/t/vector-declaration-error/43230/1 "2021-01-23T21:46:15Z")

</div>

Relatively new to ROOT so this could be a simple human error!

Hello! I’m trying to analyze data from a tree. I had ROOT generate analyze.C and analyze.h from my tree, edited analyze.C to do some analysis I need, and am trying to compile/run it but getting errors. In particular, trying

> g++ -O analyze analyze.C `root-config --cflags --libs`

gives a set of errors of repeating

> analyze.h:57: error: ISO C++ forbids declaration of ‘vector’ with no type  
> analyze.h:57: error: expected ‘;’ before ‘\<’ token

(there are a bunch of these then a bunch of subsequent errors I’m pretty sure are just stemming from this vector issue)

The lines in question in analyze.h look like

> vector\< double\> \*Hit\_t;  
> vector \< double\> \*Hit\_posx;  
> vector\< double\> \*Hit\_posy;  
> vector\< double\> \*Hit\_E;

for example. I’m reasonably sure that there isn’t actually a problem with the root file itself or the simulation the data is comping from considering it works and others use it fine, and it seems weird that the issue would be in a file automatically generated by ROOT.

First post here so let me know if there’s more information that could be useful!

_ROOT Version:_ 5.34.21  
_Platform:_ Ubuntu installed on Windows connected to server  
_Compiler:_ trying g++ here but also tried inside ROOT

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 23, 2021, 10:00pm UTC](https://root-forum.cern.ch/t/vector-declaration-error/43230/2 "2021-01-23T22:00:27Z")

</div>

Attach your “analyze.h” file for inspection.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 23, 2021, 10:34pm UTC](https://root-forum.cern.ch/t/vector-declaration-error/43230/4 "2021-01-23T22:34:15Z")

</div>

Either replace all “`vector<...`” with “`std::vector<...`” (preferred) or right after “`#include <vector>`” add “`using std::vector;`” (deprecated).

---

<div class="post-metadata">

**Author:** ![jmg](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/e68b1a/32.png) [@jmg](https://root-forum.cern.ch/u/jmg)\
**Post date:** [January 23, 2021, 10:40pm UTC](https://root-forum.cern.ch/t/vector-declaration-error/43230/5 "2021-01-23T22:40:18Z")

</div>

Added the std:: before all the vectors. Now I get

> /usr/lib/…/lib64/crt1.o: In function `\_start’:

> (.text+0x20): undefined reference to `main’

> collect2: error: ld returned 1 exit status

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [January 23, 2021, 10:50pm UTC](https://root-forum.cern.ch/t/vector-declaration-error/43230/6 "2021-01-23T22:50:17Z")

</div>

You need to follow “usage instructions” shown in the generated “analyze.C” file.

Maybe you need to have a look at the: [“ROOT User’s Guide” -\> “Trees” -\> “Using TTree::MakeClass”](http://root.cern.ch/root/html534/guides/users-guide/Trees.html#using-ttreemakeclass)

If you want to create a “standalone application”, try something like this:

```cpp
// ... add the source code below into the original "analyze.C" file ...
#if !defined( __CINT__ ) && !defined( __CLING__ ) && !defined( __ACLIC__ )
// "Standalone Application" entry point
int main(int /*argc*/, char** /*argv*/) {
  analyze *t = new analyze(); // create an "analyze" instance
  // t->Show(0); // just for fun
  // open an output file for any histograms created in "t->Loop();" below
  TFile *f = TFile::Open("analyze.root", "recreate");
  t->Loop(); // loop through all tree entries
  f->Write(); // store all "owned" objects (e.g. histograms)
  delete f; // automatically deletes any "owned" objects, too
  delete t; // cleanup
  return 0; // success
}
#endif /* !defined( __CINT__ ) && !defined( __CLING__ ) && !defined( __ACLIC__ ) */

```
