473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Initializing static class member

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;
----

Thanks,
Avi
Jul 19 '05 #1
14 10609
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. Please post to a Windows
programming newsgroup. Find one in this:

http://www.slack.net/~shiva/welcome.txt

or in the FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

--
Attila aka WW
Jul 19 '05 #2

"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bk**********@newstree.wise.edt.ericsson.se...
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.
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.
Jul 19 '05 #3
WW
jeffc wrote:
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bk**********@newstree.wise.edt.ericsson.se...
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.
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.


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.

--
WW aka Attila
Jul 19 '05 #4

"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...
jeffc wrote:
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bk**********@newstree.wise.edt.ericsson.se...
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?"
Jul 19 '05 #5
WW
jeffc wrote:
"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...
jeffc wrote:
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bk**********@newstree.wise.edt.ericsson.se...
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;
--
WW aka Attila
Jul 19 '05 #6

"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...

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.
Jul 19 '05 #7
WW
jeffc wrote:
"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...

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.


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

--
WW aka Attila
Jul 19 '05 #8

"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...
jeffc wrote:

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.


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.
Jul 19 '05 #9
WW
jeffc wrote:
"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...
jeffc wrote:

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.


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.

--
WW aka Attila
Jul 19 '05 #10

"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...

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.
Jul 19 '05 #11
WW
jeffc wrote:
"WW" <wo***@freemail.hu> wrote in message
news:bk**********@phys-news1.kolumbus.fi...

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.


Stop trolling!

--
WW aka Attila
Jul 19 '05 #12
"jeffc" <no****@nowhere.com> wrote in message news:<3f********@news1.prserv.net>...
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bk**********@newstree.wise.edt.ericsson.se... [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
Jul 19 '05 #13

"Marcelo Pinto" <mp****@tecnolink.com.br> wrote in message
news:e3**************************@posting.google.c om...
"jeffc" <no****@nowhere.com> wrote in message news:<3f********@news1.prserv.net>...
"Attila Feher" <at**********@lmf.ericsson.se> wrote in message
news:bk**********@newstree.wise.edt.ericsson.se...

[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?
Jul 19 '05 #14
WW
jeffc wrote:
[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?


Stop trolling!

--
WW aka Attila
Jul 19 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steven T. Hatton | last post by:
Is there a way to initialize an member array of user defined objects that is declared static const? For example: const vec3f I(1,0,0); const vec3f j(0,1,0); class corner_functor {
2
by: Neno | last post by:
Hi, I have a linkage error that has something to do with the use of a static member array and I can't understand how to solve the problem. Can someone help me please? In detail: A class Month...
2
by: utab | last post by:
Dear all, I am confused at some point on the initialization of static map member of a class. The class I have designed id something like this. class Class_name{ public: private:
17
by: Calle Pettersson | last post by:
Coming from writing mostly in Java, I have trouble understanding how to declare a member without initializing it, and do that later... In Java, I would write something like public static void...
14
by: Madhav | last post by:
hi all, I was trying the following code on the MS .net compiler: class Item { static int count; public: //static void init() { } Item()
8
by: John | last post by:
Hello, is there any compiler option for g++ for initializing static members of the class. Due to some unknown reason, static member in one of our c++ application is not getting initialized...
6
by: Grey Alien | last post by:
class A { public: A(const B& ref); private: static B& b ; }; How may b be initialized ?
9
by: Christopher | last post by:
Code compiles, but the string evaluates to NULL in debugger. Using gcc 3.1.1. Did I not initialize the string properly or is this a compiler bug? // some.h #include <string> namespace ns {
3
by: Ramesh | last post by:
Hi, I am trying to create an array of pointers to member functions inside my class. When I created a global array of type pfn & initialized with member functions and copy it back to the member...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.