473,396 Members | 2,029 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,396 software developers and data experts.

Initialization of members in h file

Hi all,

I just wanted to know if I can ininialize data members in the header.
The compiler (gcc 2.96) returns an error.
The data members are not const (I know that const members can't be
initiated in the header).

Does anyone no the reason?

Thanks alot,
Bari

Apr 10 '06 #1
3 1652
Bari wrote:
I just wanted to know if I can ininialize data members in the header.
Only static ones and only ones of a const integral type.
The compiler (gcc 2.96) returns an error.
That's a very old compiler. Try something newer.
The data members are not const (I know that const members can't be
initiated in the header).
Huh?
Does anyone no the reason?


The reason is that the Standard prohibits initialisation of non-static
data members anywhere except the constructor initialiser list, and also
prohibits initialisation of static members if they are non-const or if
they are of non-integral type.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 10 '06 #2
Bari <ba*******@gmail.com> wrote:

I just wanted to know if I can ininialize data members in the header.
The compiler (gcc 2.96) returns an error.
-- header.h --
class test
{
int i;
int const j;
public:
test () : i (0), j (0) {}
};
-- end header.h --

This should work .. ?
The data members are not const (I know that const members can't be
initiated in the header).


See above. They can be initialized there as well. Either I am
misunderstanding what you are trying to do, or you are misunderstanding
how and where you can initialize stuff.

hth
--
jb

(reply address in rot13, unscramble first)
Apr 10 '06 #3
??
if in ansi c?
"Bari" <ba*******@gmail.com>
??????:11*********************@g10g2000cwb.googleg roups.com...
Hi all,

I just wanted to know if I can ininialize data members in the header.
The compiler (gcc 2.96) returns an error.
The data members are not const (I know that const members can't be
initiated in the header).

Does anyone no the reason?

Thanks alot,
Bari

Apr 11 '06 #4

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

Similar topics

1
by: Jacek Dziedzic | last post by:
Hi! A) Why isn't it possible to set a member of the BASE class in an initialization list of a DERIVED class constructor (except for 'calling' the base constructor from there, of course)? I even...
3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
19
by: JustSomeGuy | last post by:
I have a class that has a static member variable. string x; x should never change during use and should be intialized to "abcd". How does one do this?
13
by: Nolan Martin | last post by:
How would I go about calling a function before the main function is called? The function needs to be called multiple times from different locations. I have something like this working but it is...
4
by: Anton Pervukhin | last post by:
Hi everybody! I have a small problem regarding the initialization of pointer to the file stream under some conditions. Imagine a class which has a pointer to output file stream and some...
4
by: Jacek Dziedzic | last post by:
Hello! Suppose I have a class Foo that defines a default c'tor that initializes some data using an initialization list: Foo::Foo() : member1(0), member2(0), member3(NULL), member4(20) // and...
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
3
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
5
by: ssylee | last post by:
I'm not sure if I can initialize members of a struct the lazy way. For example, let's say I have a struct defined as below: typedef struct _ABC { BOOL A; BOOL B; BOOL C; } ABC;
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...
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
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,...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.