Expert C Programming

(Jeff_L) #1
later.

I submitted a formal paper (document number X3J16/93-0121) to the C++ standardization committee,
suggesting that all five of the availability keywords should begin with "p", by renaming friend to
protégé (this would also promote internationalization and express the asymmetry of the relationship
in a way that friend doesn't).The keyword virtual should be renamed to placeholder, and the
descriptive term "pure," which has nothing to do with availability, should be renamed to "empty." This
would slightly increase the lexical orthogonality in the language, and if the committee liked the
experiment they could extend it to more significant semantic areas of the language. [2] No word yet on
whether they'll go for it...


[2] This is not a facetious suggestion: the misnamed const keyword in standard C causes very


real problems. Here is an opportunity to avoid similar problems and bring consistency to a
thorny area in C++.


Declarations

The declarations are just regular C declarations of functions, types (including other classes), or data.
The class binds them together. Each function declaration in the class needs an implementation, which
can be inside the class or (usually) separated out. So the whole thing may look like:


class Fruit { public: peel(); slice(); juice();


private: int weight, calories_per_oz;


};


// an instance of the class


Fruit melon;


Remember, C++ comments start with // and go to the line end.


Programming Challenge


Try Compiling and Running a C++ Program...


It's time to try a C++ program. C++ source files usually have an extension of .cpp or .cc
or .C. Create such a file, type in the above code, and add a "hello world" main program.
Declare a couple of objects of the fruit class.


On many systems, you invoke the C++ compiler by:


CC fruit.cpp

Free download pdf