Brian DiRito wrote:
setDocumentLocator is declared in DocuemntHandler as

virtual void setDocumentLocator(const Locator *const locator)

my understanding of this function is that by saving a reference to the Locator later methods can query that locater to get line numbers (and other things Locator can provide). In return we have to be careful not to alter or delete the Locator.
It's not a reference -- it's a pointer.


In java this method is declared as
void setDocumentLocator(Locator locator)
and examples found online do things such as

 public void setDocumentLocator(Locator locator) {
   this.locator = locator;
 }
(and then presumably using this.locator in later callbacks)

The catch is because the c++ declares the argument as a const Locator *const such an assignment is impossible [without a cast].
All you need to to is declare the variable as a pointer to a const Locator, and assignment is not a problem:

class myClass : public DefaultHandler
{
public:

  myClass() :
    DefaultHandler(),
    m_locator(0)
  {
  }

  virtual void
  setDocumentLocator(const Locator* const locator)
  {
    m_locator = locator;
  }

private:

  const Locator* m_locator;
}

BTW, the Xerces-C User list is a more appropriate forum for this type of post.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to