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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:33:04+00:00 2026-05-16T08:33:04+00:00

I made the following program #include <iostream> #include <typeinfo> template<class T> struct Class {

  • 0

I made the following program

#include <iostream>
#include <typeinfo>
template<class T>
struct Class
{
    template<class U>
    void display(){

        std::cout<<typeid(U).name()<<std::endl;
        return ;
    }

};


template<class T,class U>
void func(Class<T>k)
{
    k.display<U>(); 

}

int main()
{
    Class<int> d;
    func<int,double>(d);
}

The above program doesn not compile because display() is a template member function so a qualification of .template before display() must be done. Am I right?

But when I made the following program

#include <iostream>
#include <typeinfo>

template<typename T>
class myClass
{
    T dummy;
    /*******/
public:
    template<typename U>
    void func(myClass<U> obj);

};

template<typename T>
template<typename U>

void myClass<T>::func(myClass<U> obj)
{
    std::cout<<typeid(obj).name()<<std::endl;
}
template<class T,class U>
void func2(myClass<T>k)
{
    k.template func<U>(k); //even it does not compile

}
int main()
{
    myClass<char> d;
    func2<char,int>(d);
    std::cin.get();
}

Why k.func<char>(k); does not compile even after giving a .template construct?

  • 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-16T08:33:05+00:00Added an answer on May 16, 2026 at 8:33 am

    The < symbol means both “less than” and “begin template arguments.” To distinguish between these two meanings, the parser must know whether the preceding identifier names a template or not.

    For example consider the code

    template< class T >
    void f( T &x ) {
        x->variable < T::constant < 3 >;
    }
    

    Either T::variable or T::constant must be a template. The function means different things depending which is and which isn’t:

    1. either T::constant gets compared to 3 and the Boolean result becomes a template argument to T::variable<>
    2. or T::constant<3> gets compared to x->variable.

    The to disambiguate, the template keyword is required before either variable or constant. Case 1:

    template< class T >
    void f( T &x ) {
        x->template variable < T::constant < 3 >;
    }
    

    Case 2:

    template< class T >
    void f( T &x ) {
        x->variable < T::template constant < 3 >;
    }
    

    It would be kind of nice if the keyword were only required in actual ambiguous situations (which are kind of rare), but it makes the parser much easier to write and it prevents such problems from catching you by surprise.

    For standardese, see 14.2/4:

    When the name of a member template
    specialization appears after . or ->
    in a postfix-expression, or after
    nested-name-specifier in a
    qualified-id, and the
    postfix-expression or qualified-id
    explicitly depends on a
    template-parameter (14.6.2), the
    member template name must be prefixed
    by the keyword template. Otherwise the
    name is assumed to name a
    non-template.

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

Sidebar

Ask A Question

Stats

  • Questions 524k
  • Answers 524k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try something like this: from django.utils.importlib import import_module def select_view(request,… May 16, 2026 at 9:54 pm
  • Editorial Team
    Editorial Team added an answer This line from your rules is completely wrong: -A RH-Firewall-1-INPUT… May 16, 2026 at 9:54 pm
  • Editorial Team
    Editorial Team added an answer You will loose you Intellisense in the views inside quotes… May 16, 2026 at 9:54 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Consider the following program #include <iostream> #include<cstdlib> using namespace std; class E { public:
Very simple question, I made the following program : #include <stdlib.h> int main(int argc,
I'm learning linked lists, and want to know whether the following program (basically InsertAtEnd
I have made the following linked list which is not printing the list .The
I made a Powershell function just now and saved it to a ps1 file.
I'm trying to run the following code in eclipse but the console remains blank
I have a situation where I want my program to read in some numbers
So on Project Euler the Problem 4 states the following: A palindromic number reads
im new to delphi. and also almost new to programming world. i was made
I have a java program that connects to a MySql database and it's working

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.