By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,131 Members | 1,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,131 IT Pros & Developers. It's quick & easy.

static members of template classes

P: n/a
Hello !

I have here template class with
static members. and I put definition of the static member in the same
..h file where the class was declared.

however, we are getting very stange errors, because static member
occupy same place as some other non-static variables. and so
application crashes. compiler somehow allocates same place for them.

I first thought that it is because definition of static member should
be done inside translation unit (that is inside cpp file). otherwise
One Definition Rule is broken.
but in the case of template classes I do not know exactly. C++
standard says it is ok to put definition of static member into same .h
file.

then I moved definition of static member to cpp file, application
stopped crashing, but Purify still shows ABW errors.

does somebody know - is wrong or not to put definition of static
member of template class into same .h file?

I am using 2.96 gcc (g++) compiler.

thanks !

br.,
Alibek.
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Alibek" <al*****@yahoo.com> wrote...
I have here template class with
static members. and I put definition of the static member in the same
.h file where the class was declared.

however, we are getting very stange errors, because static member
occupy same place as some other non-static variables. and so
application crashes. compiler somehow allocates same place for them.

I first thought that it is because definition of static member should
be done inside translation unit (that is inside cpp file). otherwise
One Definition Rule is broken.
but in the case of template classes I do not know exactly. C++
standard says it is ok to put definition of static member into same .h
file.

then I moved definition of static member to cpp file, application
stopped crashing, but Purify still shows ABW errors.

does somebody know - is wrong or not to put definition of static
member of template class into same .h file?
It's not wrong.

I am using 2.96 gcc (g++) compiler.


You're using a compiler that is at least five years old. Change
your compiler.

Victor
Jul 22 '05 #2

P: n/a
Thank You very much. this is most probably will solve my problem.
2.95.3 compiler shows many problem which 2.96 simply ignored.

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:<NnuDb.402601$ao4.1326410@attbi_s51>...
"Alibek" <al*****@yahoo.com> wrote...
I have here template class with
static members. and I put definition of the static member in the same
.h file where the class was declared.

however, we are getting very stange errors, because static member
occupy same place as some other non-static variables. and so
application crashes. compiler somehow allocates same place for them.

I first thought that it is because definition of static member should
be done inside translation unit (that is inside cpp file). otherwise
One Definition Rule is broken.
but in the case of template classes I do not know exactly. C++
standard says it is ok to put definition of static member into same .h
file.

then I moved definition of static member to cpp file, application
stopped crashing, but Purify still shows ABW errors.

does somebody know - is wrong or not to put definition of static
member of template class into same .h file?


It's not wrong.

I am using 2.96 gcc (g++) compiler.


You're using a compiler that is at least five years old. Change
your compiler.

Victor

Jul 22 '05 #3

P: n/a
Alibek wrote:
Thank You very much. this is most probably will solve my problem.
2.95.3 compiler shows many problem which 2.96 simply ignored.


Don't waste your time, get the GCC 3.3.2 compiler.

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.