C++ Basics Review

C++ Basics Review

Classes

Defines the organization of a data user-defined type.

Members can be
Data
Functions/Methods

Information Hiding Labels
public
private
protected

Constructors

We have two in this example
Why?

additionnal syntax and accessors
Initializer list
Init data members directly in the constructor

Explicit constructor
Avoids automatic type conversion (and resulting bugs)

Constant member functions
Examines, but does not change the object state
Also called ‘accessor’
Non-const functions are called ‘mutators’

Interface Vs. Implementation
Interface typically defined in .h files
#include in .c file

Preprocessor commands

Guards against multiple inclusion of .h files
Scoping operator
To identify the class corresponding to each function

Remember
Function signatures must match in both interface and implementation
Default parameters are specified only in the interface

Main function

Objects are declared just like primitive data types.

Legal Declarations
Intcell obj1; // zero parameter constructor

Intcell obj2(12); // one parameter constructor

Illegal declarations
Intcell obj3 = 37; // explicit constructor used

Intcell obj4(); // function declaration

Vectors

Replaces built-in C++ arrays
Built-in arrays do not act as proper C++ objects

Standard vector class
Gives a size() function
Can be assigned using =

Similarly C++ also provides standard string class.

Cours gratuitTélécharger le cours complet

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *