473,378 Members | 1,346 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,378 software developers and data experts.

initializing static members of class

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 properly.

Please help me on this.

Thanks,
Prakash
May 28 '07 #1
8 2746
On 28 Maj, 16:25, "John" <prakash.mi...@gmail.comwrote:
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 properly.
Most probable reason for this is that you do not initialize it in the
code, but you have not shown us any code so we can't tell.

--
Erik Wikström

May 28 '07 #2
John wrote:
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 properly.
You mean the version you use has a bug that ignores your initialization
sometimes? In that case, I doubt that it has a compiler switch to turn that
off.

May 28 '07 #3

"John" <pr***********@gmail.comwrote:
is there any compiler option for g++ for initializing static
members of the class?
Not that I know of. Normally, the programmer initializes that,
not the compiler.
For some unknown reason, static member in one of our c++
application is not getting initialized properly.
Probably because the programmer failed to initialize it.
Please help me on this.
Ok.

Initialize the static members in the source code (not the
header!) for the module.

Example: I have a module called blat1, with header blat1.h
and source blat1.cpp. This module has a class called dumbo
with a static member called asdf. Then, initialize asdf in
blat.cpp, like so:

// in blat1.h:
class dumbo
{
public:
static int asdf;
}

// in blat1.cpp, at global scope:
dumbo::asdf (42);
--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org
May 28 '07 #4
On 5ÔÂ28ÈÕ, ÏÂÎç11ʱ47·Ö, "Robbie Hatley" <bogus.addr...@no.spamwrote:
"John" <prakash.mi...@gmail.comwrote:
is there any compiler option for g++ for initializing static
members of the class?

Not that I know of. Normally, the programmer initializes that,
not the compiler.
For some unknown reason, static member in one of our c++
application is not getting initialized properly.

Probably because the programmer failed to initialize it.
Please help me on this.

Ok.

Initialize the static members in the source code (not the
header!) for the module.

Example: I have a module called blat1, with header blat1.h
and source blat1.cpp. This module has a class called dumbo
with a static member called asdf. Then, initialize asdf in
blat.cpp, like so:

// in blat1.h:
class dumbo
{
public:
static int asdf;

}

// in blat1.cpp, at global scope:
dumbo::asdf (42);
maybe this works
int dumbo::asdf=42;

May 28 '07 #5
comp.lang.c++ wrote:
On 5ÔÂ28ÈÕ, ÏÂÎç11ʱ47·Ö, "Robbie Hatley" <bogus.addr...@no.spamwrote:
>"John" <prakash.mi...@gmail.comwrote:
>>is there any compiler option for g++ for initializing static
members of the class?

Not that I know of. Normally, the programmer initializes that,
not the compiler.
>>For some unknown reason, static member in one of our c++
application is not getting initialized properly.

Probably because the programmer failed to initialize it.
>>Please help me on this.

Ok.

Initialize the static members in the source code (not the
header!) for the module.

Example: I have a module called blat1, with header blat1.h
and source blat1.cpp. This module has a class called dumbo
with a static member called asdf. Then, initialize asdf in
blat.cpp, like so:

// in blat1.h:
class dumbo
{
public:
static int asdf;

}

// in blat1.cpp, at global scope:
dumbo::asdf (42);
maybe this works
int dumbo::asdf=42;
Or

int dumbo::asdf(42);

(that's what Robbie probably meant).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 28 '07 #6
On May 28, 7:30 pm, Erik Wikström <eri...@student.chalmers.sewrote:
On 28 Maj, 16:25, "John" <prakash.mi...@gmail.comwrote:
Hello,
is there any compiler option for g++ for initializing static members ofthe
class.
Due to some unknown reason, static member in one of our c++ application is
not getting initialized properly.

Most probable reason for this is that you do not initialize it in the
code, but you have not shown us any code so we can't tell.

--
Erik Wikström
FYI

Here is the code:

Application is using below mentioned template class which is declared
as static in RuleEngine.h class file.

static RWTPtrHashDictionary<RWCString, RuleClass
RWDefHArgs(RWCString)>ruleHash;
RWTPtrHashDictionary<RWCString, RuleClass RWDefHArgs(RWCString)>
RuleEngine::ruleHash(RWCString::hash);

Above line definition/initialization for ruleHash is found in
RuleEngine.C at the beginning of the file.

Here is sample piece of code where ruleHash is used. This code is
RuleEngine.C. I am calling insertRule(this) static method from
RuleClass.h class file.

Void RuleEngine::insertRule( RuleClass* newRule )
{
RuleClass* rule = NULL;
if( 0 != ruleHash.entries() )
............
Core dump....

}

Application is using template object ruleHash to call entries()
method.
I am getting core dump at releHash.entries() line. Its not only with
entries method, it crashes for any methods of RWTPtrHashDictionary.
I have also tried with other template class RWTValDlist<RWCStringto
test whether it is problem with deprecated RWTPtrHashDictionary
template.
But I see that application crashes for RWTValDlist template too.

Please help me.

Thanks,
Prakash

May 28 '07 #7
On May 28, 9:29 pm, prakash.mi...@gmail.com wrote:
On May 28, 7:30 pm, Erik Wikström <eri...@student.chalmers.sewrote:
On 28 Maj, 16:25, "John" <prakash.mi...@gmail.comwrote:
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 properly.
Most probable reason for this is that you do not initialize it in the
code, but you have not shown us any code so we can't tell.
--
Erik Wikström

FYI

Here is the code:

Application is using below mentioned template class which is declared
as static in RuleEngine.h class file.

static RWTPtrHashDictionary<RWCString, RuleClass
RWDefHArgs(RWCString)>ruleHash;

RWTPtrHashDictionary<RWCString, RuleClass RWDefHArgs(RWCString)>
RuleEngine::ruleHash(RWCString::hash);

Above line definition/initialization for ruleHash is found in
RuleEngine.C at the beginning of the file.

Here is sample piece of code where ruleHash is used. This code is
RuleEngine.C. I am calling insertRule(this) static method from
RuleClass.h class file.

Void RuleEngine::insertRule( RuleClass* newRule )
{
RuleClass* rule = NULL;
if( 0 != ruleHash.entries() )
............
Core dump....

}

Application is using template object ruleHash to call entries()
method.
I am getting core dump at releHash.entries() line. Its not only with
entries method, it crashes for any methods of RWTPtrHashDictionary.
I have also tried with other template class RWTValDlist<RWCStringto
test whether it is problem with deprecated RWTPtrHashDictionary
template.
But I see that application crashes for RWTValDlist template too.

Please help me.

Thanks,
Prakash
It seems RWCString::hash is constructed after the
RuleEngine::ruleHash(and result is unpredictable)...
Use Singleton pattern to fix that.

May 28 '07 #8

"Victor Bazarov" <v.********@comAcast.netwrote in message news:mp******************************@comcast.com. ..
int dumbo::asdf(42);

(that's what Robbie probably meant).
Ah, yes... good catch. For some reason I tend to forget
to include the type declarator when defining static class
members. My compiler keeps yelling at me about that. :-)

--
Cheers,
Robbie Hatley
East Tustin, CA, USA
lonewolf aatt well dott com
triple-dubya dott tustinfreezone dott org
Jun 2 '07 #9

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

Similar topics

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...
5
by: john smith | last post by:
Hi, I am trying to initialize a float in a class. For example: class ABC{ public:
2
by: Drew McCormack | last post by:
I am getting an error in g++ 4.0.0 that I did not get in g++ 3.4. I have a header with the following const variables with namespace scope: namespace Periphery { extern const double...
2
by: Daniel Switkin | last post by:
Hi there, I'm trying to do the following: class tLimits { static const int kIntMin = 0; // fine static const float kFloatMin = 0.0f; // breaks }; and I get this message:
3
by: Diebels | last post by:
Hi, I have some problems using static variables which results in a core dump. I have attached code and coredump to the end of my message. I am trying to implement a kind of factory design. I...
12
by: jimmij | last post by:
Hi, Please look at the code bellow /*******************/ class ctab { private: static const unsigned n=48;
10
by: sunil | last post by:
Hello, I am new to c# . I have some basic programming doubts. Please help me in clarifying these doubts. I want to initialize a static and readonly field with a value returned by a static...
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 {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.