Article View: alt.comp.lang.learn.c-c++
Article #351Re: class definition
From: Linda Sherman
Date: Tue, 30 Nov 1999 00:00
Date: Tue, 30 Nov 1999 00:00
31 lines
1825 bytes
1825 bytes
Ron Natalie wrote:
>
> derived::derived() : base('d') { ...
>
> This would ininitialize the base class with the char literal 'd'.
Just to add to Ron's otherwise excellent explanation, a more real-world
example might be:
class GameBoard {
private:
int rows;
int cols;
public:
GameBoard( int n_rows, int n_cols )
: rows( n_rows ), cols( n_cols ) {}
GameBoard( const GameBoard& src ) // copy constructor
: rows( src.rows ), cols( src.cols ) {}
};
class ChessBoard {
public:
ChessBoard() : GameBoard( 8, 8 ) {}
ChessBoard( const ChessBoard& src ) // copy constructor
: GameBoard( src ) {}
};
Lin
--
Linda K Sherman <lindash@concentric.net>
linsherm@gte.net www.cti-pro.com www.dalati.com
Technical Details
Message-ID:
<38442544.3B4DFC3@gte.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38436F07.55AD215F@netvigator.com> <3843E40D.3E345FBA@sensor.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,1c86b0ff88e63dee X-Google-Attributes: gidf8d38,public X-Google-Thread: 109fba,1c86b0ff88e63dee X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,1c86b0ff88e63dee X-Google-Attributes: gid114592,public From: Linda Sherman <linsherm@gte.net> Subject: Re: class definition Date: 1999/11/30 Message-ID: <38442544.3B4DFC3@gte.net> X-Deja-AN: 554983444 Distribution: world Content-Transfer-Encoding: 7bit References: <38436F07.55AD215F@netvigator.com> <3843E40D.3E345FBA@sensor.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Abuse-Info: Otherwise we will be unable to process your complaint properly X-Complaints-To: abuse@gte.net X-Trace: /bV2//2Pg/QN3LEHV2/4IskvwkgFAPM+1ljgPFI6Np/Skb6vtEJIJnP9xOfBaaJ4gGgAee/gtnxS!84+B5XqtvCJtzjULs8ACs69ECQQz4y3mooFQyYWCJoKBMeM3w+M= MIME-Version: 1.0 NNTP-Posting-Date: Tue, 30 Nov 1999 20:13:10 GMT Newsgroups: alt.comp.lang.learn.c-c++,comp.lang.c++,borland.public.cpp.language