Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5938721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:43:33+00:00 2026-05-22T15:43:33+00:00

Possible Duplicate: Where and why do I have to put “template” and “typename” on

  • 0

Possible Duplicate:
Where and why do I have to put “template” and “typename” on dependent names?

This is a specific instance of the question: Officially, what is typename for?

I am asking for the specific reason that the compiler is NOT aware that the following is a type:

#include <set>
#include <vector>

template<typename T>    // T is a type, right?
void f(const char name[], const std::vector<T>& foo) // typename NOT needed here
{
  for(std::set<T>::iterator itr =  // here, it is needed

If I declare:

std::set<int>::iterator itr; // no problem

The above clearly defines that T is a type, so why is typename required in one and not the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:43:34+00:00Added an answer on May 22, 2026 at 3:43 pm

    While you’ve links to a thorough answer, it’s a lot to wade through. So – put as simply as I can – the point is that the compiler does indeed know that T is a type as you say, but using that information and even having seen the included source code for std::set, it can’t be sure whether the iterator identifier inside the set<T> will name a type, a function, or a variable. This might seem surprising as if you look at the set<> template you can work it out, but remember that somewhere between the compiler parsing your f<>() template and before it’s instantiated, a specialisation for set<T> may be specified that uses identifier for a non-type, or simply lacks it altogether.

    So, the typename keyword just tells the compiler, hey – whatever happens you can expect iterator to name a type, and perform some validatition of the f<>() template code on that basis without waiting to see an instantiation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Where and why do I have to put the “template” and “typename”
Possible Duplicate: Where and why do I have to put the “template” and “typename”
Possible Duplicate: Where and why do I have to put the “template” and “typename”
Possible Duplicate: Where and why do I have to put “template” and “typename” on
Possible Duplicate: Where and why do I have to put the “template” and “typename”
Possible Duplicate: How to put this code in v3 instead v2 map I have
Possible Duplicate: Officially, what is typename for? Where and why do I have to
Possible Duplicate: How is this put in the center using CSS? I have tried
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: How to parse JSON in JavaScript I have this JSON string: [{title:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.