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

A deleted function in C++ is a function explicitly declared with the `= delete;` specifier, instructing the compiler to intentionally disable its usage. When a function is marked as deleted, any attempt to call it, form a pointer to it, or otherwise reference it results in a hard compile-time error.

```cpp theme={"dark"}
return_type function_name(parameters) = delete;
```

## Overload Resolution Mechanics

Unlike functions that are simply undeclared, deleted functions are fully visible to the compiler during name lookup and actively participate in overload resolution.

If a deleted function is evaluated as the best viable candidate for a given function call, the compiler terminates the compilation process and emits an error. This mechanism ensures that the compiler does not silently fall back to a less optimal, non-deleted overload or an implicit type conversion.

```cpp theme={"dark"}
void process(int x);
void process(double x) = delete;

// If called with a double:
// process(3.14); // ERROR: Call to deleted function. 
// It does NOT implicitly convert 3.14 to int to call process(int).
```

## Applicability

The `= delete` specifier can be applied to any function type, including:

* **Special Member Functions:** Default constructors, copy/move constructors, and copy/move assignment operators.
* **Normal Member Functions:** Standard class methods.
* **Non-Member (Free) Functions:** Functions declared outside of any class scope.
* **Function Templates:** Entire templates or explicit template specializations.

```cpp theme={"dark"}
template <typename T>
void allocate(T* ptr);

// Deleting an explicit template specialization
template <>
void allocate<void>(void* ptr) = delete; 
```

## Technical Rules and Constraints

**1. First Declaration Requirement**
A function must be declared as deleted on its very first declaration within a translation unit. You cannot declare a function normally and then attempt to delete it in a subsequent redeclaration or definition.

```cpp theme={"dark"}
struct Entity {
    void initialize(); 
};

// ERROR: Cannot delete a function after it has been declared.
// void Entity::initialize() = delete; 
```

**2. One Definition Rule (ODR)**
A deleted function is considered to have a definition. Because it is defined (as deleted), providing a standard body `{ ... }` elsewhere in the program violates the One Definition Rule and results in a compiler error.

**3. Interaction with Access Specifiers**
In the C++ compilation pipeline, overload resolution occurs before access control checks. If a deleted function is declared `private`, and a caller outside the class attempts to invoke it, the compiler may emit an error regarding "accessing a private member" rather than "calling a deleted function." To ensure the compiler yields the most accurate diagnostic regarding the deleted status, deleted functions are conventionally declared `public`.

**4. Virtual Functions**
A virtual function can be marked as deleted, but the C++ standard (`[class.virtual]`) enforces strict symmetry regarding overrides. A function with a deleted definition cannot override a function that does not have a deleted definition, and a function without a deleted definition cannot override a function with a deleted definition. Both the base virtual function and the overriding derived function must either be deleted, or neither can be deleted.

```cpp theme={"dark"}
struct Base {
    virtual void process() = delete;
    virtual void execute();
};

struct Derived : Base {
    // ERROR: Cannot override a deleted function with a non-deleted function
    // void process() override; 

    // ERROR: Cannot override a non-deleted function with a deleted function
    // void execute() override = delete; 
};
```

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