Modifying static member variable via a ctor in a DLL

V

vincent ngai

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 :)


Thanks
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top