473,386 Members | 1,710 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.

static members of template classes

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
3 1609
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Thomas Matthews | last post by:
Hi, I have three classes: Category Author Publisher Each of these classes stores its information into a database table of <ID, text>. (They are fields that have a foreign key.) There is...
18
by: Erik Arner | last post by:
Hi, I really need some help here. After upgrading to g++ 3.4 I have run into all sorts of troubles that I'm sure depends on my lack of proper understanding of C++. I would now like to get it right...
8
by: Jon Slaughter | last post by:
Is there any way to declare a member of a base class to make the itself in the derived class to be static? i.e., I have two classes class Base { protected: char *name;
13
by: Adam H. Peterson | last post by:
I just made an observation and I wondered if it's generally known (or if I'm missing something). My observation is that static protected members are essentially useless, only a hint to the user. ...
5
by: shablool | last post by:
Hi all, Could someone please explain what is wrong with this code (the compiler complains about "'int_type' is not a member of 'B'"): struct B; template <typename DerivedT> struct A {
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...
9
by: Rennie deGraaf | last post by:
I'm writing a class similar to this: #include <iostream> using namespace std; template<class t> class Foo { private: class Bar {
10
by: =?Utf-8?B?Y2FybG0=?= | last post by:
Hello, I searched for an answer to my question and found similar posts, but none that quite addressed the issue I am trying to resolve. Essentially, it seems like I need something like a virtual...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
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: 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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.