C++ CPE key terms
C++ CPE · Get comfortable with the vocabulary.
- translation unit
- Related: preprocessor directive, one definition rule, header guard
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.
- preprocessor directive
- Related: translation unit, macro, header guard
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.
- header guard
- Related: preprocessor directive, one definition rule
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.
- one definition rule
- Related: translation unit, inline function, declaration
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.
- declaration versus definition
- Related: one definition rule, extern, translation unit
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.
- extern
- Related: declaration versus definition, linkage, one definition rule
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.
- linkage
- Related: extern, static storage duration, translation unit
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.
- fundamental types
- Related: sizeof operator, integral promotion, const qualifier
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.
- const qualifier
- Related: constexpr, reference, fundamental types
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.
- constexpr
- Related: const qualifier, literal type
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.
- reference
- Related: const qualifier, pass by reference, pointer
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.
- pointer
- Related: reference, nullptr, dynamic allocation
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.
- nullptr
- Related: pointer, implicit conversion
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.
- pass by reference
- Related: reference, const qualifier, copy constructor
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.
- overloading
- Related: implicit conversion, default argument, operator 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.
- default argument
- Related: overloading, declaration versus definition
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.
- implicit conversion
- Related: overloading, integral promotion, explicit constructor
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.
- integral promotion
- Related: implicit conversion, overloading, fundamental types
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.
- scope
- Related: namespace, lifetime, static storage duration
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.
- lifetime
- Related: scope, static storage duration, dynamic allocation
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.
- static storage duration
- Related: lifetime, linkage, scope
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.
- namespace
- Related: scope, translation unit
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.
- class versus struct
- Related: access specifier, encapsulation
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.
- access specifier
- Related: class versus struct, encapsulation, friend function
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.
- encapsulation
- Related: access specifier, constructor
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.
- constructor
- Related: member initializer list, copy constructor, destructor
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.
- member initializer list
- Related: constructor, default constructor
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.
- default constructor
- Related: constructor, member initializer list
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.
- copy constructor
- Related: copy assignment, pass by reference, destructor
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.
- copy assignment
- Related: copy constructor, rule of three
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.
- destructor
- Related: constructor, dynamic allocation, rule of three
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.
- rule of three
- Related: copy constructor, copy assignment, destructor
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.
- explicit constructor
- Related: implicit conversion, 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.
- this pointer
- Related: member function, operator overloading
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.
- static member
- Related: static storage duration, member function
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.
- friend function
- Related: access specifier, operator overloading
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.
- operator overloading
- Related: friend function, this pointer, 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.
- inheritance
- Related: virtual function, access specifier, polymorphism
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.
- virtual function
- Related: polymorphism, pure virtual function, inheritance
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.
- pure virtual function
- Related: virtual function, polymorphism
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.
- polymorphism
- Related: virtual function, inheritance, pure virtual function
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.
- dynamic allocation
- Related: destructor, pointer, lifetime
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.