Modifying static member variable via a ctor in a DLL

Discussion in 'C++' started by vincent ngai, Nov 24, 2004.

  1. vincent ngai

    vincent ngai Guest

    Hi folks, I have the following scenario

    Lib X
    class A
    A(){ B<A>::foobar=666;

    template<> class B
    statc int foobar;

    A lib with 1 class and 1 template class with a static var, the ctor of the
    class initialises the templated class's var.
    This works if Lib X has static linkage but fubars entirely with dynamic
    linkage. I'm guessing its a memory space issue
    because tracing the address &foobar shows a different value when its
    executing the ctor and when its in the main().
    Could someone explain or point me to an explaination of how the ctor
    executing in dll changes a different static var?

    I'm basically trying to get automatic class registering via a static proxy
    ala OSG plugin style. All my dynamically
    registered classes would be derived from a base class....say Component. And
    I would have another class that
    contains a vector of Component* so that the behaviour of this container
    class can change during runtime by reading
    class id's off a txt file etc...And I won't have to know what kind of
    component the container contains because they
    are from the same base type. There are other ways to get this to work....but
    this requires minimal programmer code
    when writing new classes and I thought it's cool :)

    vincent ngai, Nov 24, 2004
    1. Advertisements

  2. vincent ngai

    David White Guest

    This question is platform-specific, and as such is off-topic here. This
    might point you in the right direction:

    David White, Nov 24, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.