473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1621
"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.********@com Acast.net> wrote in message news:<NnuDb.402 601$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
2052
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 only one table for each instance of these classes (IOW,
18
5738
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 once and for all, if possible. Most severe is the problem illustrated by the code below. It's based on the "pluggable factory pattern" described...
8
1626
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
7689
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. They don't actually protect any encapsulation or anything, and for all the actual protection they offer, they might as well be public. For...
5
1864
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
5696
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 have a base class with several sub classes. In runtime I want to create a instance of a sub class and assign it to a base class pointer. Nothing...
9
1499
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
1448
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 static function (which I know is illegal), but, is there a way to provide something similar? The class that is the target of my inquiry is a...
17
8358
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 the function if possible" (because if the compiler has the function definition available at an instantiation point, it will estimate whether to...
0
7740
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7985
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.