Dave, thank you very much for taking the time to do this. I followed up my post below with another one later last night about an idea I hit upon that is essentially what you are saying below. I'm using a static member function, getInstance() that initializes the X libraries only on the first call and then instantiates a Profile class with 'new' and returns a pointer to the instance. As with your method below, the X library initialization occurs before the parserLiaison constructs as member data and everyone is happy. It appears to be working fine. I'll read your suggestions below more thoroughly for things I could do to improve my implementation.
Thanks again for all your help, -will -----Original Message----- From: David Bertoni [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 14, 2007 4:28 PM To: xalan-c-users@xml.apache.org Subject: Re: Problem evaluating XPath expressions Will Sappington wrote: > Hi Dave, > > I think I may have hit a dead end with this. When I define > XalanSourceTreeParserLiaison _parserLiaison; as member data, the program > crashes with an assertion during construction of the Profile class. The > first line of the constructor doesn't even execute so the assertion is > occurring in the construction of the member classes. I stepped into it > and found that it occurs during construction of the parserLiaison when > it calls XalanMemMgrs::getDefaultXercesMemMgr() which is what > XALAN_DEFAULT_MEMMGR is #defined as. After that call there is an assert > (ptr != 0) and that is where the crash occurs. I'm assuming this is > because neither of the ::initialize() methods have been called. Of > course there's no opportunity to do so prior to member data construction > so it would appear I'm screwed. Is there a way to instantiate a memory > manager such that the getDefaultXercesMemMgr() call would be able to > find it? If you're going to do Xerces-C and Xalan-C initialization in the constructor of your class, you'll need to create a simple class that initializes Xerces-C and Xalan-C in the right order, and make that class a member of your class, ensuring that it appears before any other Xerces-C or Xalan-C class in the class definition. Here's an example, in pseudo-code: class XercesXalanInit { public: XercesXalanInit() { if (++s_initCount == 1) { PlatformUtils::Initialize(); XalanTransformer::initialize(); } } ~XercesXalanInit() { if (--s_initCount == 0) { XalanTransformer::terminate(); PlatformUtils::Terminate(); } } static unsigned long s_initCount; }; XercesXalanInit::s_initCount = 0; class myClass { public: myClass() : m_init(), m_liason() { } // all my public member functions here... private: XercesXalanInit m_init; XalanSourceTreeParserLiaison m_liason; }; Ultimately, it's much better if you initialize Xerces-C and Xalan-C _once_, when your application starts, and not when each instance is created. Also, you'll notice that I put some counting in the XercesXalanInit init class, because you should only call them each once. Finally, if your application will be multi-threaded, you will either need to initialize the libraries once, before any threads start, or make the counting in XercesXalanInit thread-safe. Dave