# C++: error: redefinition of 'class X' / multiple definition — missing include guard

**Code:** `redefinition of` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

The same class, struct or function body was included twice in one translation unit because the header has no include guard.

## Meaning

When two headers both include `shape.h`, the compiler sees the class definition twice and reports a redefinition. Add `#pragma once` or an `#ifndef` guard to every header, and never define non-inline functions or variables in headers.

## Common causes

- Header without `#pragma once` or `#ifndef` guard
- Two guards with the same macro name in different headers
- Including a .cpp file instead of its header
- Function or variable defined (not just declared) in a header

## Quick fix

1. Add `#pragma once` as the first line of each header
2. Use unique guard names like `MYAPP_SHAPE_H`
3. Include headers only, never .cpp files

## Detailed fix by platform

### C++

1. Put `#pragma once` at the top of every header, or wrap it in `#ifndef/#define/#endif`
2. Move function bodies to a .cpp file, or mark them `inline`

## Code examples

### Header guard

```cpp
// shape.h
#pragma once            // or: #ifndef APP_SHAPE_H / #define APP_SHAPE_H ... #endif

class Shape {
public:
    virtual double area() const = 0;
    virtual ~Shape() = default;
};
```

## How to diagnose

1. **Include chain** — Is the header reachable through two paths?
2. **Guard** — Does every header have a unique guard?
3. **Source** — Did something #include a .cpp?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/redefinition-of-class)
