need typename before dependent name C/C++ Origin: Application & API Last updated 15 Oct 2026

C++: error: need 'typename' before 'T::iterator' because 'T' is a dependent scope

Inside a template, a name like T::iterator could be a type or a value, so C++ requires the typename keyword to say it is a type.

Exact message you may see need 'typename' beforebecause is a dependent scopemissing 'typename' prior to dependent type nameexpected a type, gotthere are no arguments to that depend on a template parameter
Seen on: C/C++ GCC Clang

Meaning

When the compiler parses a template it does not yet know what T is, so T::value_type is assumed to be a value. Prefix it with typename. The same idea applies to calling member templates, which need .template / ->template.

Common causes

  • Using T::iterator, T::value_type or std::vector<T>::const_iterator as a type inside a template without typename
  • Calling a member template on a dependent object without .template
  • Using a dependent base class member without this->

⚡ Quick fix

  1. Write typename T::iterator it = c.begin();
  2. Use auto for iterators
  3. Qualify base members with this-> or Base<T>::

Detailed fix by platform

C++

  1. In C++20, typename is optional in many contexts, but not all — add it when the compiler asks
  2. auto it = c.begin(); avoids the problem completely

Code examples

typename in a template

cpp
#include <vector>

template <typename C>
void show(const C& c) {
    // C::const_iterator it = c.begin();        // error: need 'typename' before 'C::const_iterator'
    typename C::const_iterator it = c.begin();  // OK
    for (; it != c.end(); ++it) { /* ... */ }
}

int main() { show(std::vector<int>{1, 2, 3}); }

How to diagnose

  1. Template — Is the name inside a template?
  2. Kind — Is the dependent name a type?
  3. Base — Is the member from a dependent base class?

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

does not name a type — C++: error: 'string' does not name a type (C/C++)does not name a typeexpected ';' 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-…no match for 'operator' — C++: error: no match for 'operator<<' (operand types are 'std::ostream' and 'X') (C/C++)no match for 'operato…stray in program — C/C++: error: stray '\342' in program (smart quotes or invisible characters) (C/C++)stray in programtemplate argument deduction/substitution failed — C++: error: template argument deduction/substitution failed / couldn't deduce template parameter (C/C++)template argument ded…was not declared in this scope — C++: error: 'x' was not declared in this scope (undeclared identifier) (C/C++)was not declared in t…need type…

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.