RE: [ROOT] Problems with typedef of STL map & vector

From: Philippe Canal (pcanal@fnal.gov)
Date: Fri Nov 05 2004 - 17:37:02 MET


Hi,

I tried to load you example with ACLiC in 3.10/02 and I had no problem with
   dset::Dataset::Row row;
I had a different problem with
  root [2] dset::Dataset::IdList lst;
  Error: vector<string,allocator<string> >() no default constructor
FILE:(tmpfile) LINE:1
  *** Interpreter error recovered ***
This last problem would be solved by just importing the lastest CINT code in
the source of ROOT 3.10/02.

In your linkdef I would do (as ACLiC does)
  #pragma link C++ nestedclasses;
  #pragma link C++ nestedtypedefs; 
  #pragma link C++ defined_in <here i specify the location of header file
Dataset.h>

Then you can see if the typedef are correctly loaded by doing
	.typedef dset::Dataset::Name

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch [mailto:owner-roottalk@pcroot.cern.ch]
On Behalf Of vsambamu
Sent: Tuesday, November 02, 2004 10:03 AM
To: roottalk@pcroot.cern.ch
Subject: [ROOT] Problems with typedef of STL map & vector

Hi,
    I am new to ROOT and had a few problems with using the STL
vector/map class. I am using ROOT 3.10. My problem is that I am not able
to access a typedef of a vector/map inside root. My classes are like
this 

**************************
// Dataset.h
#include <string>
#include <map>
#include <vector>

#ifdef __CINT__
#pragma link C++ class std::vector<std::string>;
#pragma link C++ class std::map<std::string, std::string>;
#pragma link C++ dset::Dataset::IdList;
#endif

namespace dset {
class Dataset {
public: // typedefs
                                                                        
       
  typedef std::string Name;
  typedef std::map<std::string, std::string> Row;
  typedef std::vector<std::string> IdList;

private:
  -------
  -------
};
}

**************************
// DatasetLinkDef.h - generated by makefile

#ifdef __CINT__
                                                                        
       
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link off all typedefs;
                                                                        
       
#pragma link C++ defined_in <here i specify the location of header file
Dataset.h>
#pragma link C++ nestedclasses;
#pragma link C++ nestedtypedefs;

#endif
**************************

There are several such classes and there's a Makefile which creates the
<class>LinkDef.h file automatically for each class in the package.

There is also a program which sets up the environment and loads all the
class libraries using gSystem->load() during root startup. 

When i start root, I am able to use the "dset::Dataset::Name" typdef 
For eg: 
root [0] dset::Dataset::Name name;
root [1] name = "abc";
(string 0x8d13f48)"abc"
root [2] cout << abc << endl;
abc

But when I use the other two typedefs, I get an error
1] 
root [9] dset::Dataset::IdList lst;
Error: Symbol IdListlst is not defined in current scope  FILE:(tmpfile)
LINE:1*** Interpreter error recovered ***

2]
root [10] dset::Dataset::Row row;
Error: Symbol Rowrow is not defined in current scope  FILE:(tmpfile)
LINE:1
*** Interpreter error recovered ***

Doubt: 
I saw in one of your threads (on the root mailing list) that a similar
bug was fixed in the latest version of root (v4.0). 
Is there a solution for this in the version that I am using (v3.10)? Is
there something else I need to do for these typedefs to be recognized in
root? Any comments would be very helpful.

Thank you for your time,

Regards,
Vinay Sambamurthy



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:10 MET