Skip to content

Repo sync for protected branch #5042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 24, 2024
Original file line number Diff line number Diff line change
@@ -1,30 +1,84 @@
---
description: "Learn more about: Compiler Warning (level 2) C4150"
title: "Compiler Warning (level 2) C4150"
title: Compiler warning (level 2) C4150
ms.date: "11/04/2016"
f1_keywords: ["C4150"]
helpviewer_keywords: ["C4150"]
ms.assetid: ff1760ec-0d9f-4d45-b797-94261624becf
---
# Compiler Warning (level 2) C4150

deletion of pointer to incomplete type 'type'; no destructor called
> deletion of pointer to incomplete type 'type'; no destructor called

The **`delete`** operator is called to delete a type that was declared but not defined, so the compiler cannot find a destructor.
The `delete` operator is called to delete a type that was declared but not defined. The compiler can't find the destructor to call because the definition isn't in the same translation unit as the `delete`.

The following sample generates C4150:
## Example

The following sample generates C4150 by declaring but not defining `class IncClass`:

```cpp
// C4150.cpp
// compile with: /W2
class IncClass;
class IncClass;

void NoDestruct( IncClass* pIncClass )
{
delete pIncClass; // C4150
}
```

To fix the issue, put the definition of `IncClass` in the same file as the `delete`. If the class is declared in a header file, it can be added to the file using `#include`. If the class isn't declared in a header file, the `NoDestruct` function definition may need to be moved into the same file as the `IncClass` definition.

```cpp
// compile with: /W2
#include "IncClass.h"

void NoDestruct( IncClass* pIncClass )
{
delete pIncClass;
} // C4150, define class to resolve
}
```

C4150 will be emitted when the class is defined after the destructor call in the same file. In the following example `IncClass` is declared before being used, but defined after the `delete`:

```cpp
// C4150.cpp
// compile with: /W2
class IncClass;

int main()
void NoDestruct( IncClass* pIncClass )
{
delete pIncClass; // C4150
}

class IncClass
{
public:
IncClass() = default;
~IncClass() = default;
};
```
In this scenario, the use of `delete` needs to be after the class definition.
```cpp
// C4150.cpp
// compile with: /W2
class IncClass;

void NoDestruct( IncClass* pIncClass );

class IncClass
{
public:
IncClass() = default;
~IncClass() = default;
};

void NoDestruct( IncClass* pIncClass )
{
delete pIncClass;
}

```

## See also

* [Projects and build systems](../../build/projects-and-build-systems-cpp.md)
* [Source files and source programs](../../c-language/source-files-and-source-programs.md)