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

Initialization of members in h file

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
??
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 discussion thread is closed

Replies have been disabled for this discussion.