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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:21:28+00:00 2026-05-27T03:21:28+00:00

In C++ Primer Plus (2001, Czech Translation) I have found these different template specialization

  • 0

In C++ Primer Plus (2001, Czech Translation) I have found these different template specialization syntax:

function template

template <typename T> void foo(T);

specialization syntax

void foo(int param); // 1
void foo<int>(int param); // 2
template <> void foo<int>(int param); // 3
template <> void foo(int param); // 4
template void foo(int param); // 5

Googling a bit, I have found only No.3 examples. Is there any difference (in call, compiling, usage) among them? Are some of them obsolete/deprecated? Why not just use No.1?

  • 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-27T03:21:28+00:00Added an answer on May 27, 2026 at 3:21 am

    Here are comments with each syntax:

    void foo(int param); //not a specialization, it is an overload
    
    void foo<int>(int param); //ill-formed
    
    //this form always works
    template <> void foo<int>(int param); //explicit specialization
    
    //same as above, but works only if template argument deduction is possible!
    template <> void foo(int param); //explicit specialization
    
    //same as above, but works only if template argument deduction is possible!
    template void foo(int param); //explicit instantiation
    

    Added by me:

    //Notice <int>. This form always works!
    template void foo<int>(int param); //explicit instantiation
    
    //Notice <>. works only if template argument deduction is possible!
    template void foo<>(int param); //explicit instantiation
    

    From coding point of view, overload is preferred over function-template-specialization.

    So, don’t specialize function template:

    • Why Not Specialize Function Templates?
    • Template Specialization and Overloading

    And to know the terminologies:

    • instantiation
    • explicit instantiation
    • specialization
    • explicit specialization

    See this :

    • Difference between instantiation and specialization in c++ templates
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read C++ Primer, and it says function template specialization is an advanced topic,
I've just started working through C++ Primer Plus and I have hit a little
Working through C++ Primer Plus and am trying to cin data to a dynamically
I'm learning C++ at the moment, C++ Primer plus. But I just felt like
From C Primer Plus 5th Ed: Write a program that creates two eight-element arrays
I'm working through 'C Primer Plus', was just going through the programming exercises and
I'm trying to self-study C using C Primer Plus from Stephen Prata and one
Im reading c++ primer plus and having some issues understanding how implicit instantiation works.
I'm doing a programming question from C++ Primer Plus which asks me to make
While reading C++ Primer Plus 5th edition, I saw this piece of code: cin.get(ch);

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.