RE: [ROOT] Problem with stl map

From: Matthew Wood (mdwood@midway.uchicago.edu)
Date: Wed Jul 30 2003 - 11:59:12 MEST


Hi.  I am still confused by the implementation of STL in ROOT.  For
example the following code with vectors works fine:

#include<vector>

int vec() {

  vector< double > vec;
  vector< double >::iterator vit;

  vec.push_back(5.0);

  vit=vec.begin();
  
  cout << *vit << endl;

  return 0;

}

But to do the same thing with map I have to go through this business of
precompiling my own library.  Furthermore I can't figure out how to get
map iterators to work properly.  I tried the following:

#include<map>

int map {

  map< long, double, less< long > > m; 
  map< long, double, less< long > >::iterator mit;
  m[3]=4.5;
  mit=m.begin();
  cout << mit->first << endl;

  return 0;

}

but got the error:

Error: Symbol mit is not defined in current scope  FILE:test.C LINE:17
Error: Failed to evaluate mit->first(class G__CINT_ENDL)143141208
*** Interpreter error recovered ***

I tried including the line

#pragma link C++ class map<long,double,less<long> >::iterator;

in the MapLoader.C file and recompiled the library but that didn't work
either.  Thank you again for your help.

Matthew Wood

On Tue, 29 Jul 2003, Philippe Canal wrote:

> Hi Matthew,
> 
> You should compile you map (rather than trying to use the interpreted
> version).
> The message means that there are already some map instance that has been
> compiled.
> 
> Do:
>    // MapLoader.C
>    #include <map>
>    #pragma link C++ class map<long,double,less<long> >;
>    // End of MapLoader.C
> 
>    root [] .L MapLoader.C+
> 
> Cheers,
> Philippe.
> 
> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Matthew Wood
> Sent: Tuesday, July 29, 2003 8:16 AM
> To: roottalk@pcroot.cern.ch
> Subject: [ROOT] Problem with stl map
> 
> 
> Hi.  I am having trouble using the STL map class and I was hoping someone
> could give me an example that works.  I tried the same code in a C++
> program and it worked fine.  Here is what I am trying ( I am using ROOT
> 3.05/05 ):
> 
> root [0] #include <map>
> root [1]test;
> Limitation: Can't instantiate precompiled template
> map<long,double,less<long> > FILE:(tmpfile) LINE:1
> *** Interpreter error recovered ***
> 
> Thank you for your help.
> 
> Matthew Wood
> 



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET