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 8708223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:04:28+00:00 2026-06-13T04:04:28+00:00

I have to declare Iter as typename but no typedef . Then, I cannot

  • 0

I have to declare Iter as typename but no typedef.
Then, I cannot use Iter in my template class declaration => frustrating 🙁
Please teach me how to use Iter, or else explain me why C++ is so nasty…

template <typename T>
struct MyContainer
{
  typedef  std::vector<T>  Vec;
  typename Vec::iterator   Iter;

  void Fo (typename std::vector<T>::iterator);  //ok
  typename std::vector<T>::iterator Ba();       //ok

  void Foo (Iter);   //error: 'Iter' is not a type
  Iter Bar ();       //error: 'Iter' does not name a type
};                   //(gcc 4.1.2)
  1. Why typedef cannot be used to declare Iter? Why not?
  2. How to use Iter within the template class? (e.g. as function parameter type)

EDIT
In the instruction typename Vec::iterator Iter; the keyword typename says Vec::iterator is a type (i.e. not a static member function/attribute). Therefore, Iter is not declared as a type, but as a variable using the type Vec::iterator.

  • 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-06-13T04:04:30+00:00Added an answer on June 13, 2026 at 4:04 am
    1. typedef can be used alongside typename. So it becomes:

      typedef typename vec::iterator Iter;
      
    2. Just use Iter now.

      template <typename T>
      struct MyContainer
      {
        typedef  std::vector<T>         Vec;
        typedef typename Vec::iterator  Iter;
      
        void Foo (Iter);   //ok
        Iter Bar ();       //ok
      };
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a template class that is: template <class identifier,class registeredObject> class FxPairRegistry :
In my solution, I have created public class to store value and already declare
Can I, or do I have to declare it as a class with it's
Why does the derived class have to declare its methods as virtual for dynamic
Do I have to DECLARE all private methods in .m class file inside @interface
I have to declare n = 01 . But whenever I try it's getting
In MFC DLL Why do I have to declare theApp using CWinApp theApp;,or else
i have two table: declare @t1 table (id int) declare @t2 table (id int)
As an example, if I have a table: DECLARE @tmpTable TABLE ( SectionID INT,
I have a fun script: DECLARE @StartDT DATE DECLARE @MinDOS DATE DECLARE @TableName VARCHAR(50)

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.