CHAPTER 12

image

Class

A class is a template used to create objects. To define one the class keyword is used followed by a name, a code block and a semicolon. The naming convention for classes is mixed case, meaning that each word should be initially capitalized.

class MyRectangle {};

Class members can be declared inside the class; the two main kinds are fields and methods. Fields are variables and they hold the state of the object. Methods are functions and they define what the object can do.

class MyRectangle{   int x, y;};

Class Methods

A method belonging to a class is normally declared as a prototype inside of the class, and the actual implementation ...

Get C++ 14 Quick Syntax Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.