Initializing static class member

A

Avi Uziel

Hi All,

I'm writing a Windows DLL which contain some utility classes.
One of my classes is Singleton, therefore contain some static members.
I'm using VC6 and linking to the DLL statically.

My question is where is the correct (and best way) to initialize
theses variables? If I initialize them in the class CPP (in the DLL)
then I get linkage error when I try to link my project with the LIB,
and I don't want to make the user initialize those variables.

---- The DLL mydll.dll :
classA.h:

class DLL_EXPORT A{
static int x;
}

classA.cpp
I would like to write:

int A::x = 0;
 
J

jeffc

Attila Feher said:
Avi said:
Hi All,

I'm writing a Windows DLL which contain some utility classes.
One of my classes is Singleton, therefore contain some static members.
I'm using VC6 and linking to the DLL statically.
[SNIP]

Your question is Windows (DLL) specific.

His actual question wasn't.
My question is where is the correct (and best way) to initialize
theses variables?
classA.cpp
I would like to write:
int A::x = 0;

That is the correct way. If that doesn't work, he has some other problem.
 
W

WW

jeffc said:
Attila Feher said:
Avi said:
Hi All,

I'm writing a Windows DLL which contain some utility classes.
One of my classes is Singleton, therefore contain some static
members. I'm using VC6 and linking to the DLL statically.
[SNIP]

Your question is Windows (DLL) specific.

His actual question wasn't.

It was. Read the post.
That is the correct way. If that doesn't work, he has some other
problem.

The OP wrote:
8<===
If I initialize them in the class CPP (in the DLL)
then I get linkage error when I try to link my project with the LIB,
and I don't want to make the user initialize those variables.

===>8

He has a problem. And it very much seems to be DLL related.
 
J

jeffc

WW said:
jeffc said:
Attila Feher said:
Avi Uziel wrote:
Hi All,

I'm writing a Windows DLL which contain some utility classes.
One of my classes is Singleton, therefore contain some static
members. I'm using VC6 and linking to the DLL statically.
[SNIP]

Your question is Windows (DLL) specific.

His actual question wasn't.

It was. Read the post.

The only question in his post was "My question is where is the correct (and
best way) to initialize theses variables?"
 
W

WW

jeffc said:
WW said:
jeffc said:
Avi Uziel wrote:
Hi All,

I'm writing a Windows DLL which contain some utility classes.
One of my classes is Singleton, therefore contain some static
members. I'm using VC6 and linking to the DLL statically.
[SNIP]

Your question is Windows (DLL) specific.

His actual question wasn't.

It was. Read the post.

The only question in his post was "My question is where is the
correct (and best way) to initialize theses variables?"

If I initialize them in the class CPP (in the DLL)
then I get linkage error when I try to link my project with the LIB,
and I don't want to make the user initialize those variables.

---- The DLL mydll.dll :
classA.h:

class DLL_EXPORT A{
static int x;
}

classA.cpp
I would like to write:

int A::x = 0;
 
J

jeffc

WW said:
If I initialize them in the class CPP (in the DLL)
then I get linkage error when I try to link my project with the LIB,
and I don't want to make the user initialize those variables.

This is off topic. Please don't post off topic messages. Take this to a
Windows newsgroup.
 
W

WW

jeffc said:
This is off topic. Please don't post off topic messages. Take this
to a Windows newsgroup.

This is what the OP posted, and you have refused to read. Stop trolling.
 
J

jeffc

WW said:
This is what the OP posted, and you have refused to read. Stop trolling.

Here's what the OP posted: "My question is where is the correct (and best
way) to initialize theses variables?" Everything else was irrelevant
detail. Stop being pedantic.
 
W

WW

jeffc said:
Here's what the OP posted: "My question is where is the correct (and
best way) to initialize theses variables?" Everything else was
irrelevant detail. Stop being pedantic.

And he continued: because when I try the correct way in my DLLs it does not
work.

Stop trolling.
 
J

jeffc

WW said:
And he continued: because when I try the correct way in my DLLs it does not
work.

You thought he was off topic because you thought something about his DLL was
part of the problem. It wasn't. It had nothing to do with it. His
question was 100% on topic. The DLL was a red herring that you fell for.
If you'd stop worrying so much about your image and the party line, we'd all
be better off.
 
W

WW

jeffc said:
You thought he was off topic because you thought something about his
DLL was part of the problem. It wasn't. It had nothing to do with
it. His question was 100% on topic. The DLL was a red herring that
you fell for. If you'd stop worrying so much about your image and the
party line, we'd all be better off.

Stop trolling!
 
M

Marcelo Pinto

jeffc said:
news:[email protected]... [snip]
His actual question wasn't.
That is the correct way. If that doesn't work, he has some other problem.

His problem is with some DLL mechanism, once he has posted the right
way of initializing the static variable and reports that he is
recieving a linkage error. So it's OT in this newsgroup.

Regards,

Marcelo Pinto
 
J

jeffc

Marcelo Pinto said:
"jeffc" <[email protected]> wrote in message
news:[email protected]... [snip]
His actual question wasn't.
That is the correct way. If that doesn't work, he has some other
problem.

His problem is with some DLL mechanism, once he has posted the right
way of initializing the static variable and reports that he is
recieving a linkage error. So it's OT in this newsgroup.

He obviously wanted to know what the right way of initializing the static
variable was. Did you read the post?
 

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,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top