[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3452.0. "trouble initializing static STL map attribute" by CIM2NI::THORPE () Mon Feb 17 1997 14:36

I am getting a link-time error I think because I don't know how to
initialize a static attribute that is an STL map.

Small sample code is attached...

Thanks,
Bill

$ cxx/version nl:
DEC C++ V5.4-010 on OpenVMS Alpha V6.1
$ cxx/ass=nohead t
$ cxxlink t
%LINK-W-NUDFSYMS, 1 undefined symbol:
%LINK-I-UDFSYM,         map<int, CimObjMgr *, less<int > >
CimObjMgr::registry
%LINK-W-USEUNDEF, undefined symbol map<int, CimObjMgr *, less<int > >
CimObjMgr::registry referenced
        in psect $LINK$ offset %X00000030
	in module T file CIMENG11$:[EKD_V010.WRK.THORPE.SRC]T.OBJ;20

//t.h
#include <map>                       // STL map definitions

class ObjMgr
{
private:
  static ObjMgr *instance;
  static map<int, ObjMgr *, less<int> > registry;
protected:
  ObjMgr ( void );
public:
  static void registerObjMgr ( int classCode, ObjMgr *aObjMgr );
  static ObjMgr *makeInstance ( void );
};


//t.cxx
#include <t.h>

ObjMgr *ObjMgr::instance = NULL;

ObjMgr::ObjMgr ( void )
{
  ObjMgr::registerObjMgr ( 0, this );
}

ObjMgr *
ObjMgr::makeInstance ( void )
{
  if ( instance == NULL )
    instance = new ObjMgr;

  return instance;
}

void
ObjMgr::registerObjMgr ( int classCode, ObjMgr *aObjMgr )
{
  registry [ classCode ] = aObjMgr;
}

main ( void )
{
  ObjMgr *aObjMgr = ObjMgr::makeInstance ();
}

T.RTitleUserPersonal
Name
DateLines
3452.1SPECXN::DERAMODan D&#039;EramoMon Feb 17 1997 14:5013
	I believe these two in the class definition
        
		static ObjMgr *instance;
		static map<int, ObjMgr *, less<int> > registry;
        
        would be defined like this in t.cxx
        
		ObjMgr *ObjMgr::instance = NULL;
		map<int, ObjMgr *, less<int> > ObjMgr::registry;
        
        See also topic 3233 for how to link with a static map.
        
        Dan