Using STL vectors of non-basic type

Dear all,
I came across the following.
Define a user class:

#include <iostream>
class myclass
{
public:
  Int_t x[100];
  Int_t y[100];
  inline myclass() { }
  virtual inline ~myclass() {  }
  ClassDef(myclass,1)
    };

and then execute

so that myclass gets compiled and added to the list of classes which can be used interactively. However, if I try to make an STL vector from this class:

vector <myclass> x; x.resize(10);
then the system will crash, displaying messages like “Shared object disappeared from memory”, etc.
Is this because STL vectors of non-basic type cannot be used in the interactive sesions (only in compiled programs) ? I have written several classes which read and write trees with classes which encapsulate STL vectors of my own classes and didn’t have any trouble untill I tried to access the vectors interactively to get out some numeric values. It seems that in order to display the values stored, each time I have to write corresponding methods in my (g++ compiled) analysis classes … I made sure that I’m including and using namespace std. If I try

vector <Int_t> a;
a.resize(10);
a[0] = 0;
a[0] <ENTER> 
(int)0

in an interactive Root-session, then there is no problems. What am I doing wrong?
Thank you,
Dmitri.

I have tried to use a _linkdef.h - file with the following:

#pragma link C++ class myclass; #pragma link C++ class std::vector<myclass> and now this seems to be working. Is this the only thing that I was missing in the above code? Or should I expect more surprises (unexpected memory leaks) once I start processing large STL vectors?

Hi Dmitri,
the dictionary for your STL collection is all you need. There are large amounts of data written with STL collections, so you should be fine.
Cheers, Axel.

I’m trying to do something even simpler: use a vector.

I have the following pragma.C:

#include <vector> #ifdef __MAKECINT__ #pragma link C++ class vector<unsigned int>+; #endif

and when I do .L pragma.C+ and declare a vector I get

[quote]root [0] .L pragma.C+
Info in TUnixSystem::ACLiC: creating shared library /home/rsholmes/Compton/compton/acpa/./pragma_C.so
Note: Link requested for already precompiled class vector<unsigned int,allocator > (ignore this message) :0:
root [1] vector test
Error: vector<unsigned int,allocator >() no default constructor (tmpfile):1:
*** Interpreter error recovered ***
[/quote]

If I pay attention to the message it says to ignore, and postulate that there already is a dictionary for vector, this happens:

[quote]root [0] vector test
root [1] test.push_back(3)
Error: Can’t call vector<unsigned int,allocator >::push_back(3) in current scope (tmpfile):1:
Possible candidates are…
(in vector<unsigned int,allocator >)
*** Interpreter error recovered ***
[/quote]

What am I missing? (I’m using ROOT 5.17/02).

Hi,

For simple type, ROOT provide the dictionary (in what is a called a cint dlls).
To load it, simply do:

I.e. have the interpreter execute the #include

Note that in ROOT 5.19/04, this has been automated (i.e. typing vector willl autoload the cintdlls).

Cheers,
Philippe.