Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8797
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Ian Collins <ian-news@hotmail.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: Reference to class question |
| Date | Sun, 14 Aug 2011 08:43:44 +1200 |
| Lines | 70 |
| Message-ID | <9ao600FdeuU5@mid.individual.net> (permalink) |
| References | <af58ebd4-73e7-4392-99dc-2391f89e2640@hl8g2000vbb.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Trace | individual.net vX2InSwzNwt8ehSwo9hQGQeCJMukZlP4BCn4boTNkp7GZ0tyqf |
| Cancel-Lock | sha1:pNXSg7XQTyeGw3tScPS4a6zSZkg= |
| User-Agent | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 |
| In-Reply-To | <af58ebd4-73e7-4392-99dc-2391f89e2640@hl8g2000vbb.googlegroups.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:8797 |
Show key headers only | View raw
On 08/14/11 03:52 AM, Nephi Immortal wrote:
> Please confirm if my code is valid with no undefined behavior. When
> you create data members, any built-in types such as char, int are
> always uninitialized until you tell Constructor function to initialize
> them.
>
> What about two data members: x and y in Z class? Both x and y are
> always initialized automatically with memory address before you call
> Constructor function.
They aren't initialised with an address, they have an address. They are
part of the Z object.
> Reference is like a pointer to set up memory address. The y in Z
> class is always bound to Y class and it can’t be unbound unless you
> change from reference to pointer.
>
> struct X
> {
> X( int _x, int _y ) : x( _x ), y( _y )
> {
> }
>
> ~X()
> {
> }
>
> int x;
> int y;
> };
>
> struct Y
> {
> Y( X& _x ) : x( _x )
> {
> }
>
> ~Y()
> {
> }
>
> X&x; // reference
> };
>
> struct Z
> {
> Z( int a, int b ) : x( a, b ), y( x ) // initialized y( x )
> {
> }
>
> ~Z()
> {
> }
>
> X x;
> Y y;
> };
>
>
> int main()
> {
> Z z( 1, 2 );
>
> return 0;
>
> }
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
Reference to class question Nephi Immortal <immortalnephi@gmail.com> - 2011-08-13 08:52 -0700 Re: Reference to class question Ian Collins <ian-news@hotmail.com> - 2011-08-14 08:43 +1200
csiph-web