MESSAGE
DATE | 2010-03-10 |
FROM | Ruben Safir
|
SUBJECT | Re: [NYLXS - HANGOUT] C++ Workshop _ Syntax Basics Structs Unions
|
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.
|
|