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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:54:06+00:00 2026-05-30T01:54:06+00:00

A template argument can be a constant expression (§C.5), the address of an object

  • 0

A template argument can be a constant expression (§C.5), the address of an object or function with external linkage (§9.2), or a non-overloaded pointer to member (§15.5). A pointer used as a template argument must be of the form &ooff, where ooff is the name of an object or a function, or of the form ff, where ff is the name of a function. A pointer to member must be of the form &XX::ooff, where ooff is the name of an member. In particular, a string literal is not acceptable as a template argument.

This is from stroustrup book. What’s the logic behind what’s allowed and what’s not? Why string literal is not acceptable?

My understanding is that compiler should be able to deduce the type of the argument, so that it can generate code internally for that given type. Thanks for the help

  • 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-30T01:54:07+00:00Added an answer on May 30, 2026 at 1:54 am

    The compiler does not deduce types of non-type template arguments. They are specified by the programmer. There’s nothing to deduce.

    The requirements are in place to ensure that the compiler can determine, at compile time, whether two pointers are equal. This, in turn, is needed to determine whether two uses of a class template (function template) refer to the same type (function).

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

Sidebar

Related Questions

A C++11 template function which takes a function object argument, such as: template <typename
What can I use to dereference a template argument if it's a pointer (or
How can I specify what is required to be a valid template argument? What
I'm trying to write code that uses a member typedef of a template argument,
Can C-Style strings be used as template arguments? I tried: template <char *str> struct
I would like to pass a function as a template argument to another function
How can I define a template class which provides an integer constant representing the
In C++, you can invoke method's from a template argument like so: template<class T>
When can you omit the C++ template argument list? For example in Visual Studio
How to write a template, that would take as argument classes, whose constructors have

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.