Hi, apologies if you get this twice, I am new on roottalk... I have 2 problems with STL and compiled/interpreted code. I tried several different ways, playing with dictionary and LinkDef, but at the end I can get the same behaviour with the following very simplified examples which reimplements a sort on a vector<int>. <file myless.C> class myless { public: bool operator()( const int &a, const int &b) { return a < b; } }; </file> <file test.C> #include "myless.C" #include <algorithm> #include <vector> #include <iostream> void test() { vector<int> v; v.push_back(1); v.push_back(3); v.push_back(2); // sort(v.begin(),v.end()); sort(v.begin(),v.end(),myless()); cout << v[0] << " " << v[1] << " " << v[2] <<endl; } </file> with this example, > .L test.C++ > test() work perfectly, while > .L test.C > test() gives: Error: Constructor myless((myless)(141656792)) not found FILE:algo.h LINE:864 *** Interpreter error recovered *** I guess this is due to the fact that STL sort is expecting a pointer to the operator (or whatever it is) and this cannot be understood by CINT, so the only way is to compile it? Now imagine I want to have a compiled function that does the sort for me. <file mysort.C> #include <algorithm> #include <vector> #include <iostream> class mysort { public: static void doSort(vector<int> &vpar) { sort(vpar.begin(),vpar.end()); } }; </file> this is what I get in a sample session: root [0] #include <vector> root [1] vector<int> v root [2] v.size() (const unsigned int)0 root [3] .L mysort.C++ Info in <ACLiC>: creating shared library ./mysort_C.so Class mysort: Streamer() not declared Class mysort: ShowMembers() not declared root [4] v.size() (const unsigned int)0 root [5] vector<int> v2 root [6] v2.size() Error: Can't call vector<int,__malloc_alloc_template<0> >::size() in current scope FILE:/tmp/filek1D2K9_cint LINE:1 Possible candidates are... filename line:size busy function type and name (in vector<int,__malloc_alloc_template<0> >) Error: Symbol v2 is not defined in current scope FILE:/tmp/filek1D2K9_cint LINE:1 Error: Failed to evaluate v2.size()Possible candidates are... filename line:size busy function type and name *** Interpreter error recovered *** i.e. after loading a file that actually instantites a vector<int>, it is not possible to use it interactively. I guess that this is due to the fact that the compiler creates a concrete type out of the template and this overrides the CINT template. How can I use a vector both in compiled and interpreted codes? I could not find useful information in roottalk. I am using version 3.03.02. Thanks, Nicola ----------------------------------- Nicola Amapane []=- INFN +39-011-6707374 // _-=__-= CERN +41-22-7671519 _/|] ) ___ \ Mobile/SMS +39-(0)3471411410 (_) \___/_(___)_| mailto:nicola.amapane@cern.ch @ @
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:00 MET