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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:32:32+00:00 2026-06-09T15:32:32+00:00

I read on a website that the declaration template <int x> int func() {

  • 0

I read on a website that the declaration

template <int x>
int func() {
  return x;
} 

is valid while the following is not

template <double x>
double func() {
  return x;
}

Why is the first a legal declaration for a template function while the second is not?

  • 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-09T15:32:34+00:00Added an answer on June 9, 2026 at 3:32 pm

    It is not valid because it is not an integral type. There are certain restrictions on nontype template parameters and this is one of them, which says …

    Floating-point numbers and class-type objects are not allowed as nontype template parameters.

    template <double VAT>       // ERROR: floating-point values are not
    double process(double v) { // allowed as template parameters
        return v * VAT;
    }
    
    template <std::string name> // ERROR: class-type objects are not
    class MyClass {             // allowed as template parameters
      /* ... */
    };
    

    The above is quoted from C++ Templates. I take no credits for it.

    The reason why they are not valid for template initialization, as per my understanding, is because types like float and double don’t have a defined implementation in C++. So when a template like

    template <double VAT> double process(double v);
    

    is initialized with two different double values as

    template <(double) 2/3> double process(2.3)
    
    template <(double) 1/3> double process(2.4);
    

    they might not have same bit representation because of double nontype, which confuses the compiler.

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

Sidebar

Related Questions

If we have a website with multiple images and videos, I've read that it's
Original Question: i read that for RESTful websites. it is not good to use
Let's say I have N > 1 TCP-based, connection-oriented (read: not a website) services
I have read on the adobe website that you could use php with flex.I
I have a website that uses Basic Authentication (username/password). Why is the following code
I have read it on the official website that there are several ways in
If it is possible to read information from a website that is organized using
I have a lot of pages on my website that are the following format:
I read from sun website that for every reference jvm is creating one immutable
I read from the enterprise db website that only the Postgres standard server and

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.