TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Geo
from: Gregg N
date: 2004-11-18 19:13:02
subject: Re: C++ for beginners?

From: "Gregg N" 

Geo wrote:
> "Gregg N"  wrote in message
> news:419c0ffb{at}w3.nls.net...
>
>>     Operands(T a, T b) : a_(a), b_(b) { }
>
> what's the a_(a) stuff about?
>
> Geo.

A common convention is to stick an underscore at the beginning or end of
the name of a class member variable. In this case, a_ and b_ are the names
of the two variables that will store the operands. Another convention
commonly used Windows-based code is to use an m_ prefix.

The sequence

: a_(a), b_(b)

is an example of a constructor initializer list. It tells the compiler how
to provide arguments for the construction of the object's own member
objects. In this case the member objects are just built-in types, so I
could have done this as

Operands(T a, T b)
{
   a_ = a;
   b_ = b;
}

but that won't work for member objects whose constructors require
arguments, and is conceptually wrong because it theoretically means you are
constructing a_ and b_ and then assigning to them. For non-trivial objects
this would be inefficient.

Gregg

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.