Re: Expat-discuss Digest, Vol 77, Issue 10

Albrecht Fritzsche <[email protected]>
Newsgroups gmane.text.xml.expat.general
Message-ID <Pine.SOL.4.58.0608281330300.9017@twen>

On Mon, 28 Aug 2006 [email protected] wrote:

> Is there any way how i can access them?
>
> Heres the code:
>
> struct Wrapper {
>
> public:
>
>      bool LHS_is_on, RHS_is_on, rule_is_on;
>
>    static void  XMLCALL startElement(void *userData, const XML_Char
> *name, const XML_Char **atts)
>    {
>      if(strcmp(name, "LHS") == 0) {
>        LHS_is_on = true;
>        RHS_is_on, rule_is_on = false;
>      }
>    }
> ...
> };
>
> So i don't have a lot of knowledge about c++ it would be great if
> your answers (hopefully there are any :)) would be as simple as
> possible so i can understand it :)

Uh, that makes it hard to write C++ code, doesn't it?

This *is* actually about understanding some fundamental
principles - objects, static class data, ...

Inside the static function you try to access a (as I assume)
non-static member of Wrapper. If, as I assume, userData is
a pointer to an Wrapper object, you can write in

   startElement(...) {
     Wrapper* wrapper = static_cast<Wrapper*>(userData);
     if (...) {
       wrapper->LHS_is_on = ...
     }
   }

ie you get access to the Wrapper object through the userData
pointer, which needs to be re-casted to an Wrapper object
inside of each static function.

HTH
Ali
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.