Error: Can't call vector<tdiEntry,allocator<tdiEntry> >

Hi,

I have written the following class (you pass it a line from a file which gets tokenized then the first four elements can be returned)

class tdiEntry{
    private:
    vector<string>  entry;

    public:
    tdiEntry(){};
    tdiEntry(string str);
    string getDescription(){return entry[0];}
    string getType(){return entry[1];}
    string getId(){return entry[2];}
    string getValue(){return entry[3];}
};

tdiEntry::tdiEntry(string str)
{
    const string delimiters = " ";
    // Skip delimiters at beginning.
    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
    // Find first "non-delimiter".
    string::size_type pos     = str.find_first_of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
        // Found a token, add it to the vector.
        entry.push_back(str.substr(lastPos, pos - lastPos));
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of(delimiters, pos);
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}

Then I get the following when trying to use CINT

root [0] #include "tdiEntry.C"
root [1] #include <vector>
root [2] tdiEntry *item = new tdiEntry("trial item")
root [3] vector<tdiEntry> myVector
root [4] myVector.push_back(item)
Error: Can't call vector<tdiEntry,allocator<tdiEntry> >::push_back(item) in current scope (tmpfile):1:
Possible candidates are...
(in vector<tdiEntry,allocator<tdiEntry> >)
/home/radu/Desktop/IRootTracer/Tracer/AutoDict_vector_tdiEntry__cxx.so  -1:-1   0 public: void vector<tdiEntry,allocator<tdiEntry> >::push_back(const tdiEntry& x);
*** Interpreter error recovered ***

I have found a few other topics that were similar to this but still do not know how to fix it. Could someone please explain why this is happening and how to fix it?

Radu

Hi,

Use.L tdiEntry.C+ #include <vector>and the rest should work correctly.

Cheers,
Philippe.

Now I get

root [0] .L tdiEntry.C+
Info in <TUnixSystem::ACLiC>: creating shared library /home/radu/Desktop/IRootTracer/Tracer/./tdiEntry_C.so
root [1] #include <vector>
root [2] tdiEntry *item = new tdiEntry("trial item")
root [3] vector<tdiEntry> myVector
root [4] myVector.push_back(item)
Error: Can't call vector<tdiEntry,allocator<tdiEntry> >::push_back(item) in current scope (tmpfile):1:
Possible candidates are...
(in vector<tdiEntry,allocator<tdiEntry> >)
/home/radu/Desktop/IRootTracer/Tracer/AutoDict_vector_tdiEntry__cxx.so  -1:-1   0 public: void vector<tdiEntry,allocator<tdiEntry> >::push_back(const tdiEntry& x);
*** Interpreter error recovered ***

Radu

Strange … which version of ROOT are you using?

Try:.L tdiEntry.C+ #include <vector> gInterpreter->GenerateDictioanry("vector< tdiEntry>","tdiEntry.C;vector");
Cheers,
Philippe.

Version 5.29/03 21 April 2011

root [0] .L tdiEntry.C+
root [1] #include <vector>
root [2] gInterpreter->GenerateDictioanry("vector< tdiEntry>","tdiEntry.C;vector");
Error: Can't call TCint::GenerateDictioanry("vector< tdiEntry>","tdiEntry.C;vector") in current scope (tmpfile):1:
Possible candidates are...
*** Interpreter error recovered ***

When I was trying to create that vector withing the application I am working on right now three other files were created

  1. AutoDict_vector_tdiEntry_.cxx
#include "vector"
#include "tdiEntry.C"
#ifdef __CINT__ 
#pragma link C++ nestedclasses;
#pragma link C++ nestedtypedefs;
#pragma link C++ class vector<tdiEntry>+;
#pragma link C++ class vector<tdiEntry>::*;
#ifdef G__VECTOR_HAS_CLASS_ITERATOR
#pragma link C++ operators vector<tdiEntry>::iterator;
#pragma link C++ operators vector<tdiEntry>::const_iterator;
#pragma link C++ operators vector<tdiEntry>::reverse_iterator;
#endif
#endif
  1. AutoDict_vector_tdiEntry__cxx.d

# DO NOT DELETE

AutoDict_vector_tdiEntry__cxx.so: tdiEntry.C
AutoDict_vector_tdiEntry__cxx.so: /home/radu/Desktop/sources/root-trunk/include/cintdictversion.h /home/radu/Desktop/sources/root-trunk/include/RVersion.h
AutoDict_vector_tdiEntry__cxx__ROOTBUILDVERSION= 5.29/03
  1. AutoDict_vector_tdiEntry__cxx.so

Hi,

The real problem is thattdiEntry *item = new tdiEntry("trial item"); vector<tdiEntry> myVector; myVector.push_back(item);is illegal C++ as the vector expects object and ‘item’ is a pointer. You need either:tdiEntry *item = new tdiEntry("trial item"); vector<tdiEntry*> myVector; myVector.push_back(item);ortdiEntry item("trial item"); vector<tdiEntry> myVector; myVector.push_back(item);ortdiEntry *item = new tdiEntry("trial item"); vector<tdiEntry> myVector; myVector.push_back(*item);

root [2] gInterpreter->GenerateDictioanry("vector< tdiEntry>","tdiEntry.C;vector"); Error: Can't call TCint::GenerateDictioanry("vector< tdiEntry>","tdiEntry.C;vector") in current scope is a typo, the actually function name is GenerateDictionary. (But you probably do not really need it)

Cheers,
Philippe.

Well that makes perfect sense. My C++ programming skills are not up to par yet. Thank you very much for such prompt responses.

Radu

I have similar problem, but cannot solve it with the above.

I do

.L code.cpp++ run("filename")
the code is (in brief)

... vector<TH1D*> histograms; ... histograms.push_back(new TH1D(...)); fill... draw...
ok up to here.
Then in the interactive/interpreter I try to access the histograms, but:
although it sees the vector:

>histograms (class vector<TH1D*>)140681640470768
it does not allow access (or I do not know how to).

>histograms.at(0) Error: Can't call vector<TH2D*,allocator<TH2D*> >::at(0) in current scope (tmpfile):1: Possible candidates are... (in vector<TH1D*,allocator<TH1D*> >) *** Interpreter error recovered ***

The error you show has “TH2D” in it, while your vector is supposed to use “TH1D”.

my bad.
edited.

Hi,

The best solution is to move to ROOT v6.

With ROOT v5, you will need to generate the dictionary for the vector for CINT to know about it:

Cheers,
Philippe.