does not name a type C/C++ Origin: Application & API Last updated 15 Oct 2026

C++: error: 'string' does not name a type

Where the compiler expected a type, it found a name it does not know as one — a missing header, namespace, or class declared later.

Exact message you may see does not name a typeerror: 'string' does not name a typeerror: 'vector' does not name a typehas not been declaredunknown type name
Seen on: C/C++ GCC Clang

Meaning

At global or class scope, the compiler only accepts declarations. An unknown word there is reported as "does not name a type". It usually means the type's header is missing, std:: is missing, a typo, or the type is defined further down.

Common causes

  • Missing #include <string> / <vector> and similar
  • Missing std:: prefix at namespace or class scope
  • Typo or wrong letter case
  • Class used before its definition (needs a forward declaration)
  • Statement placed at global scope (code outside any function)

⚡ Quick fix

  1. Add the header and std:: prefix
  2. Forward-declare the class or reorder definitions
  3. Move statements into a function such as main()

Detailed fix by platform

C++

  1. #include <string> then std::string name;
  2. Check that code like x = 5; is inside a function, not at file level

Code examples

Statement outside a function

cpp
#include <string>

std::string name;
name = "Ada";          // error: 'name' does not name a type (assignment at global scope)

int main() {
    name = "Ada";      // OK
}

How to diagnose

  1. Scope — Is this at file or class level?
  2. Header — Is the type's header included?
  3. Order — Is the type defined above this line?

🔧 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):

call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…comparison of integers of different signs — C/C++: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' [-Wsign-compare] (C/C++)comparison of integer…declared and not used — Go: declared and not used: x / "fmt" imported and not used (Go)declared and not usedE0308 — Rust: error[E0308]: mismatched types — expected `X`, found `Y` (Rust)E0308expected ';' before — C/C++: error: expected ';' before 'x' — missing semicolon (C/C++)expected ';' beforeexpected primary-expression before — C++: error: expected primary-expression before ')' token (C/C++)expected primary-expr…expected unqualified-id before — C++: error: expected unqualified-id before 'return' / before ')' token (C/C++)expected unqualified-…incomplete type — C++: error: invalid use of incomplete type 'class X' — forward declaration only (C/C++)incomplete typedoes not …

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.