Re: Static members of a class in a dll
On 23 sep, 18:15, Joseph M. Newcomer <newco...@flounder.com> wrote:
Grnerally, you should not be exporting variables from a DLL. You shoul=
d probably export
state setter/getter methods instead. THere are a number of things that=
can go wrong here
because of how DLLs work, and I would avoid them entirely by never, ever,=
making a static
int a public member. Make it a protected member, and add void SetValor=
(int) and int
GetValor() methods. And I don't want to hear anything about "efficienc=
y" here; it is
completely and utterly irrelevant to the discussion.
=
joe
On Thu, 23 Sep 2010 02:49:23 -0700 (PDT), Josemi <josemiant...@gmail.com>=
wrote:
Hello!
I have a curious case with a class that has a static member defined in
a DLL. Let me explain:
dll.h
class __declspec (dllexport) A
{
public:static int valor;
PrintOut ()
{
TRACE1(valor);
}
}
dll.cpp
A::valor=23;
main.h
class B:A
{
}
main.cpp
A::valor;
{
A objeto;
objeto.valor = 34;
objeto.PrintOut();
}
Well, it happens that the value given in "main.cpp" objeto.valor =
34, PrintOut print 23. Can you know what is wrong? although I have
some idea, I think the problem is that I have to declare A::valor in
the two routines and well, the compiler creates two instances of
A::valor, Is it posible declare only one in dll.cpp file? or any idea
how to solve this problem. I can think of set routines that fill this
gap, but I wanted something less complicated.
Thanks in advance
your sincerely
Josemi
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm- Ocultar texto de la cita -
- Mostrar texto de la cita -
Many thanks for your help, Joe.
I was waiting for your comment because You are usually whom help to
everyone.
Thank you very much for everything, truly and wholeheartedly