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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:42:34+00:00 2026-05-15T12:42:34+00:00

I have the following template class: template<class T> class C { typedef C_traits<T> traits;

  • 0

I have the following template class:


template<class T>
class C
{
    typedef C_traits<T>                traits;
    typedef typename traits::some_type type;
    //...
    // use 'traits' and 'type' a lot
    //...
};

where C_traits is a template struct that has a typedef for some_type that is different for each specialization of the type X. I am trying to write a function that receives a reference to a variable of type as defined above, i.e.:


template<class T>
//void f(const C_traits<T>::some_type& c)     <-- this does not work either
void f(const C<T>::type& c)
{
    //...
}

I’m getting an “expected unqualified-id before ‘&’ token” error on the line where f is defined. I think I understand why I am getting this error, but I’d like to know if there is any way to accomplish what I’m trying to do here.

Put another way, I’d like to do something like this:


template<class T>
void f(typename const C<T>::type& c)
{
    //...
}

which is not allowed. Any thoughs?

  • 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-15T12:42:35+00:00Added an answer on May 15, 2026 at 12:42 pm
    template <typename T> 
    void f(const typename C<T>::type& c) { }
    

    This is allowed, but a qualified type is one of the non-deduced contexts. That is, template argument deduction won’t work for this, so you’ll have to call the function like so:

    f(42);      // won't work
    f<int>(42); // works
    

    If you don’t want to supply the type argument explicitly, one option is to have the function just take a T:

    template <typename T> void f(const typename T& c) { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following use case: There's a class called Template and with that
I have the following code: template <typename Provider> inline void use() { typedef Provider::Data<int>
I have the following templated classes, template <typename Real> class Marker { typedef Wm5::Vector3<Real>
I have the following class template<typename hi_t, typename lo_t> struct int_t { hi_t hi;
I have the following class: template <typename T> class matrix { private: int _n;
I have the following class definition: template<typename QueueItemT> class QueueBC { protected: QueueBC() {}
I have the following code: template <class T> struct pointer { operator pointer<const T>()
I have the following scenario :- template <typename T> class Base { public: virtual
I have the following code: class TimeOutException {}; template <typename T> class MultiThreadedBuffer {
I have the following functions in class C class C { template<typename T> void

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.