redefinition of C/C++ Origin: Application & API Last updated 15 Oct 2026

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

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

Exact message you may see redefinition of 'classredefinition of 'structerror: redefinition ofprevious definition of 'classconflicting declaration
Seen on: C/C++ GCC Clang

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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Could not find a package configuration file — CMake Error: Could not find a package configuration file provided by "Foo" (requested version 1.2) (C/C++)Could not find a pack…fatal error: No such file or directory — C/C++: fatal error: foo.h: No such file or directory — #include not found (C/C++)fatal error: No such …implicit declaration of function — C: warning: implicit declaration of function 'foo' [-Wimplicit-function-declaration] (C/C++)implicit declaration …incomplete type — C++: error: invalid use of incomplete type 'class X' — forward declaration only (C/C++)incomplete typemissing separator — Make: Makefile:5: *** missing separator. Stop. (spaces instead of a tab) (C/C++)missing separatormultiple definition of — C/C++: multiple definition of `x'; first defined here — ld returned 1 exit status (C/C++)multiple definition ofNo rule to make target — Make: *** No rule to make target 'foo.c', needed by 'foo.o'. Stop. (C/C++)No rule to make targetnot a member of std — C++: error: 'optional' in namespace 'std' does not name a template type — wrong -std standard (C/C++)not a member of stdredefinit…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.