> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C++ Deleted Constructor

A deleted constructor is a constructor explicitly marked with the `= 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.

```cpp theme={"dark"}
class Widget {
public:
    // Explicitly deleting the default constructor
    Widget() = delete; 

    // Explicitly deleting the copy constructor
    Widget(const Widget&) = delete; 

    // Explicitly deleting a parameterized constructor
    Widget(int, double) = delete; 
};
```

## 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.

```cpp theme={"dark"}
class DataHandler {
public:
    DataHandler(double) {}
    DataHandler(int) = delete; // Prevents implicit conversion from int to double
};

DataHandler d1(3.14); // Compiles: Calls DataHandler(double)
DataHandler d2(42);   // Error: Overload resolution selects DataHandler(int), which is deleted
```

## 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 under `private` 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:

1. It guarantees a compile-time error, whereas the legacy approach could result in a deferred link-time error if a `friend` class or member function attempted an invocation.
2. It explicitly communicates intent to both the compiler and other developers at the syntax level.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C++ Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
