MESSAGE
| DATE | 2010-03-10 |
| FROM | Ruben Safir
|
| SUBJECT | Re: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics Structs Unions
|
From owner-hangout-outgoing-at-mrbrklyn.com Wed Mar 10 22:20:40 2010 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix) id 343003BE50; Wed, 10 Mar 2010 22:20:40 -0500 (EST) Delivered-To: hangout-outgoing-at-www2.mrbrklyn.com Received: by www2.mrbrklyn.com (Postfix, from userid 28) id 211D93C024; Wed, 10 Mar 2010 22:20:40 -0500 (EST) Delivered-To: hangout-at-nylxs.com Received: from mail1.panix.com (mail1.panix.com [166.84.1.72]) by www2.mrbrklyn.com (Postfix) with ESMTP id 85CA73BE50; Wed, 10 Mar 2010 22:20:39 -0500 (EST) Received: from panix1.panix.com (panix1.panix.com [166.84.1.1]) by mail1.panix.com (Postfix) with ESMTP id 1CF891F09C; Wed, 10 Mar 2010 22:21:00 -0500 (EST) Received: by panix1.panix.com (Postfix, from userid 20529) id 1219614B98; Wed, 10 Mar 2010 22:21:00 -0500 (EST) Date: Wed, 10 Mar 2010 22:20:59 -0500 From: Ruben Safir To: hangout-at-nylxs.com Subject: Re: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics Structs Unions and Classes - agregate data types Message-ID: <20100311032059.GA28925-at-panix.com> References: <20100309204415.GA19780-at-panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100309204415.GA19780-at-panix.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: owner-hangout-at-mrbrklyn.com Precedence: bulk Reply-To: hangout-at-mrbrklyn.com
Classes:
A great deal of the rest of our C++ workshop will be understanding, exploring and debugging Classes. In this section, I just want to take a quick pass at them in order to complete the data types section of the workshop. Classes are similar to structs and unions in that they have similar syntax and can share similar functionality. They also create new data types. In fact, they are the data type creator extraordinaire.
Classes need to be declared, defined, and implemented. The have a lot of language magic to make them work, and their detail study is all but necessary to become a good C++ coder. At their simplest level they look like this:
Class Declaration:
Class myclass;
Class Definition:
Class myclass {
public: member 1; member 2; private: exclusive member one; exclusive member two; };
//Don't Forget the Semi-colon
myclass apples; myclass apples("optional arguments"); myclass fruit = myclass("optional arguments"); myclass apples = "only one single argument";
Members that are public can be accessed like a struct:
int somevar = fruit.member1; myclass * classptr = &fruit;
int somevar = classptr->member1;
private members can not be accessed from the outside of the class.
This is all I'll say about classes for the time being. Next is flow control operators and structures.
|
|