Re: non-const static member variale initialization
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 10 Feb 2008 00:10:00 -0800
Thanks Bo Persson,
This is initializing the variable, not defining it. The definition is
on the previous line.
{
}
}
All together, this is a class definition, because it defines the
class.
Actually, I do not quite agree with you (correct me if I am wrong). I think
definition involves storage space allocation. When in a class we write int i
as a data member variable and make it public, actually the 4-byte storage is
not allcoated. The storage space is allocated in constuctor. So, my point is
I think the definition of member variable i is missing. :-)
Any comments?
regards,
George
"Bo Persson" wrote:
George wrote:.
Thanks Bo Persson,
Your reply is clear. I am confused what code in class could be
viewed as definition of a member variable. For code like this,
class Foo {
public:
int i;
Foo (int input): i (input)
This is initializing the variable, not defining it. The definition is
on the previous line.
{
}
}
All together, this is a class definition, because it defines the
class.
(On the next line I would expect either the name of a class object or
a semicolon :-).
What code do you think is member variable i definition?
A variable definition looks like this
int i;
whether it is a member of a class or not. :-)
How about code like this?
class Foo {
public:
int i;
Foo (int input)
{
i = input;
This is assigning a value to an uninitialized member variable.
}
}
Bo Persson
- Follow-Ups:
- Re: non-const static member variale initialization
- From: Igor Tandetnik
- Re: non-const static member variale initialization
- References:
- Re: non-const static member variale initialization
- From: Giovanni Dicanio
- Re: non-const static member variale initialization
- From: George
- Re: non-const static member variale initialization
- From: Bo Persson
- Re: non-const static member variale initialization
- From: George
- Re: non-const static member variale initialization
- From: Bo Persson
- Re: non-const static member variale initialization
- Prev by Date: Re: How to make a full-screen app
- Next by Date: Re: extern "C"
- Previous by thread: Re: non-const static member variale initialization
- Next by thread: Re: non-const static member variale initialization
- Index(es):
Relevant Pages
|