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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:49:02+00:00 2026-06-09T14:49:02+00:00

I am trying to pass a template typedef as argument to a function template.

  • 0

I am trying to pass a template typedef as argument to a function template. However I get following errors:

TestTemplates.cpp:11: error: expected unqualified-id before ‘&’ token

TestTemplates.cpp:11: error: expected unqualified-id before ‘&’ token

TestTemplates.cpp:11: error: expected initializer before ‘&’ token

TestTemplates.cpp:25: error: ‘func’ was not declared in this scope

#include <iostream>
#include <vector>

template<class T>
struct MyVector
{
    typedef std::vector<T> Type;
};

template<class T>
void func( const MyVector<T>::Type& myVec )
{
    for( MyVector<T>::Type::const_iterator p = myVec.begin(); p != myVec.end(); p++)
    {
        std::cout<<*p<<"\t";
    }
}

int main()
{
    MyVector<int>::Type myVec;
    myVec.push_back( 10 );
    myVec.push_back( 20 );

    func( myVec );
}

Can anyone point out how to fix this error. I have looked at some posts, but cannot find the solution. Thanks

  • 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-09T14:49:03+00:00Added an answer on June 9, 2026 at 2:49 pm

    You need to tell the compiler that it’s a typename

    void func( const typename MyVector<T>::Type& myVec )
    

    Then you need to explicitly help the compiler deduce the type for the function:

    func<int>( myVec );
    

    BTW, the issue is called “two stage lookup“

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

Sidebar

Related Questions

Trying to pass a string argument to a function, which will then be used
I'm trying to pass a member function pointer as a template parameter. Here is
I'm trying to pass the boost::geometry::get function described here to another function, but I
I am trying to pass a template into a cut filter, something like this
I'm trying to pass an array to my template with a simple tag. I
I am trying to pass a list of questions into a template in Play
I am trying pass class as value in hashmap. I need to get the
im trying to pass two parameters to a function, i being an int value
I'm trying to pass in the location of my ftl template. In MyApplication extend
I am trying to pass the following information to paypal and it s saying

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.