C++ CPE study materials
C++ CPE study resources

C++ CPE key terms

C++ CPE · Get comfortable with the vocabulary.

translation unit

The source file passed to the compiler together with everything it includes, after preprocessing. It is the unit of compilation, and its declarations must satisfy the one-definition rule across the whole program.

Related: preprocessor directive, one definition rule, header guard
preprocessor directive

A line beginning with # that the preprocessor handles before real compilation, such as #include or #define. Directives perform textual substitution and are not C++ statements, so they do not end with a semicolon.

Related: translation unit, macro, header guard
header guard

Include-guard macros or #pragma once placed at the top of a header so repeated inclusion in one translation unit only expands the contents once, preventing duplicate class and function definitions.

Related: preprocessor directive, one definition rule
one definition rule

The rule that a function or variable may be defined only once per program, while types, templates, and inline functions may be defined in several translation units provided the definitions are identical.

Related: translation unit, inline function, declaration
declaration versus definition

A declaration introduces a name and its type so the compiler can check uses; a definition also allocates storage or supplies a body. A variable can be declared many times but defined once.

Related: one definition rule, extern, translation unit
extern

A storage-class specifier that declares a variable defined elsewhere, giving the name external linkage without allocating storage here. Used in headers to share a single global object across translation units.

Related: declaration versus definition, linkage, one definition rule
linkage

The property determining whether a name can refer to the same entity across translation units. External linkage allows sharing; internal linkage (static or anonymous namespace) restricts a name to its own translation unit.

Related: extern, static storage duration, translation unit
fundamental types

The built-in arithmetic types: bool, char and its signed/unsigned variants, short, int, long, long long, float, double, and long double, plus void. Their sizes are implementation-defined except for minimum guarantees.

Related: sizeof operator, integral promotion, const qualifier
const qualifier

A type qualifier promising that an object will not be modified through that name. The compiler rejects writes, and a const object must be initialized where it is defined.

Related: constexpr, reference, fundamental types
constexpr

A specifier meaning the entity can be evaluated at compile time when given constant inputs. A constexpr variable requires a constant initializer, and a constexpr function must be usable in constant expressions.

Related: const qualifier, literal type
reference

An alias for an existing object, declared with &. A reference must be bound at initialization and cannot be reseated; a reference parameter lets a function modify its caller's argument without copying.

Related: const qualifier, pass by reference, pointer
pointer

An object holding the address of another object or function, declared with *. A pointer can be null, reassigned, and used for arithmetic within an array; dereferencing requires a valid target.

Related: reference, nullptr, dynamic allocation
nullptr

The null pointer literal of type std::nullptr_t. It converts to any pointer type but not to an integer, so it avoids the overload-resolution surprises caused by the integer literal 0.

Related: pointer, implicit conversion
pass by reference

Passing an argument so the parameter aliases the caller's object instead of copying it. Changes inside the function affect the original; a const reference parameter avoids copying large objects while forbidding modification.

Related: reference, const qualifier, copy constructor
overloading

Declaring several functions or operators with the same name but different parameter lists. The compiler selects one at compile time by comparing argument types through the ranking of exact, promotion, and conversion matches.

Related: implicit conversion, default argument, operator overloading
default argument

A value supplied in a function declaration and used when the caller omits that trailing argument. Defaults must be the rightmost parameters and may appear only once per parameter across declarations.

Related: overloading, declaration versus definition
implicit conversion

An automatic type conversion the compiler inserts, such as int to double or an array to a pointer. User-defined conversions via non-explicit constructors and conversion operators also participate in overload resolution.

Related: overloading, integral promotion, explicit constructor
integral promotion

The implicit conversion of a small integer type such as char, short, or bool to int or unsigned int before arithmetic. Promotions rank above other conversions when the compiler selects an overload.

Related: implicit conversion, overloading, fundamental types
scope

The region of source text where a name is visible, such as a block, function, class, or namespace. Inner scopes hide outer names of the same name, and the :: operator reaches outer or global names.

Related: namespace, lifetime, static storage duration
lifetime

The portion of program execution during which an object exists and may be used. Automatic objects live from definition to end of block; dynamic objects live until explicitly deleted.

Related: scope, static storage duration, dynamic allocation
static storage duration

Storage that lasts for the whole program run. Global variables, namespace-scope statics, and function-local static variables have it; a local static is initialized once on first execution.

Related: lifetime, linkage, scope
namespace

A named scope used to group declarations and prevent name collisions. Members are accessed with the scope operator, and using-declarations or using-directives bring selected names into the current scope.

Related: scope, translation unit
class versus struct

Both define a user-defined type with members and member functions. The only language difference is default access: class members and bases are private by default, struct members and bases are public.

Related: access specifier, encapsulation
access specifier

The keywords public, protected, and private that set who may use a class member: everyone, derived classes, or only the class itself and its friends. They also control inheritance visibility.

Related: class versus struct, encapsulation, friend function
encapsulation

Keeping data members private and exposing a controlled public interface of member functions. This lets the class enforce invariants and change its internal representation without breaking calling code.

Related: access specifier, constructor
constructor

A special member function with the class name and no return type that initializes a newly created object. Member initializer lists run before the body and are the only way to initialize const and reference members.

Related: member initializer list, copy constructor, destructor
member initializer list

The colon-prefixed list after a constructor's parameter list that initializes members directly. Members are initialized in declaration order, not list order, and unlisted class members are default-initialized.

Related: constructor, default constructor
default constructor

A constructor callable with no arguments, either written explicitly or implicitly generated. Declaring any other constructor suppresses the implicit one, so defaulted objects then fail to compile.

Related: constructor, member initializer list
copy constructor

A constructor taking a reference to the same class type that builds a new object as a copy of an existing one. It is used for copy initialization and for passing or returning objects by value.

Related: copy assignment, pass by reference, destructor
copy assignment

operator= taking the same class type that replaces an existing object's state with another's. Unlike the copy constructor it runs on already-constructed objects and must handle self-assignment correctly.

Related: copy constructor, rule of three
destructor

A member function named with a leading tilde that runs when an object is destroyed. It releases resources the object owns, and it is called automatically at end of scope or on delete.

Related: constructor, dynamic allocation, rule of three
rule of three

A guideline that a class needing a custom destructor, copy constructor, or copy assignment operator usually needs all three, because each signals manual management of an owned resource.

Related: copy constructor, copy assignment, destructor
explicit constructor

A constructor marked explicit that is excluded from implicit conversions and copy-initialization with =. It still works for direct initialization, and it prevents accidental temporary objects from single-argument constructors.

Related: implicit conversion, constructor
this pointer

In a non-static member function, a pointer to the object the call was made on. It distinguishes parameters from members and enables returning the current object by reference for chaining.

Related: member function, operator overloading
static member

A class member belonging to the class rather than to any object. It is accessed with the class name and must be defined outside the class if it is a non-inline static data member.

Related: static storage duration, member function
friend function

A non-member function granted access to a class's private and protected members by a friend declaration. Friendship is granted, not inherited, and it is not mutual unless declared both ways.

Related: access specifier, operator overloading
operator overloading

Defining the meaning of an operator for user-defined types through a function named operator followed by the symbol. At least one operand must be a class or enumeration type.

Related: friend function, this pointer, overloading
inheritance

Deriving a new class from an existing one so it reuses and extends the base's members. The access specifier on the base controls whether that relationship is public, protected, or private.

Related: virtual function, access specifier, polymorphism
virtual function

A member function declared virtual in a base class and dispatched at run time to the most-derived override when called through a base pointer or reference. Overrides should be marked override.

Related: polymorphism, pure virtual function, inheritance
pure virtual function

A virtual function declared with = 0 and no body in the base class, making the class abstract. Abstract classes cannot be instantiated, and derived classes must override the function to be concrete.

Related: virtual function, polymorphism
polymorphism

Selecting behavior based on the dynamic type of an object, achieved when virtual functions are called through base-class pointers or references. It lets one interface serve many derived implementations.

Related: virtual function, inheritance, pure virtual function
dynamic allocation

Creating objects at run time with new and releasing them with delete, or new[] with delete[]. Mismatching the forms is undefined behavior, and every allocation must eventually be freed exactly once.

Related: destructor, pointer, lifetime