A deleted constructor is a constructor explicitly marked with theDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
= delete specifier, instructing the compiler to intentionally disable its generation and prohibit its invocation. When a constructor is deleted, any attempt to instantiate the object using that specific constructor signature results in a hard compile-time error.
Compiler Mechanics and Overload Resolution
Unlike constructors that are simply omitted or hidden via access specifiers, deleted constructors actively participate in name lookup and overload resolution. When an object instantiation occurs, the compiler evaluates all available constructors. If the deleted constructor is determined to be the best match for the provided arguments, the compiler selects it and immediately halts compilation with an error. This mechanism ensures that the compiler does not silently fall back to a less optimal constructor or perform unintended implicit type conversions.Interaction with Special Member Functions
The C++ compiler automatically generates certain special member functions (such as the default constructor, copy constructor, and move constructor) under specific conditions. Applying= delete to these signatures suppresses this implicit generation. Once a special member function is deleted, the class ceases to possess that specific capability (e.g., becoming non-copyable or non-default-constructible).
Access Control vs. Deletion
While deleted constructors can technically be placed underprivate or protected access specifiers, standard practice dictates declaring them as public.
Because C++ checks access control before checking for deletion, placing a deleted constructor in a private block can cause the compiler to emit an access violation error rather than a “use of deleted function” error. Declaring them public ensures the compiler generates the most accurate and direct diagnostic message.
Pre-C++11 Equivalence
Prior to the introduction of= delete in C++11, developers achieved a similar effect by declaring a constructor private and intentionally omitting its implementation. However, the = delete specifier is technically superior because:
- It guarantees a compile-time error, whereas the legacy approach could result in a deferred link-time error if a
friendclass or member function attempted an invocation. - It explicitly communicates intent to both the compiler and other developers at the syntax level.
Master C++ with Deep Grasping Methodology!Learn More





