[Expat-discuss] Expat-discuss Digest, Vol 77, Issue 10

Albrecht Fritzsche ali at mental.com
Mon Aug 28 13:36:27 CEST 2006



On Mon, 28 Aug 2006 expat-discuss-request at libexpat.org 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



More information about the Expat-discuss mailing list