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

  • Home
  • SEARCH
  • 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 8880271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:08:03+00:00 2026-06-14T20:08:03+00:00

Possible Duplicate: Strings as template arguments? Why the first declaration is OK but the

  • 0

Possible Duplicate:
Strings as template arguments?

Why the first declaration is OK but the second is not? Why std::string is not suitable?

template <typename T, T x> struct foo { };

using namespace std;

int main()
{
    foo<int, 0> f_int;              // ok
    foo<string, ""> f_string;      // not ok
}

I get:

error: a non-type template parameter cannot have type 'std::basic_string<char>'

using clang++.

  • 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-14T20:08:04+00:00Added an answer on June 14, 2026 at 8:08 pm

    You simply cannot have a template parameter of type std::string. The rules for non-type template parameters are defined by the standard as follows (§14.1/4):

    A non-type template-parameter shall have one of the following (optionally cv-qualified) types:

    • integral or enumeration type,
    • pointer to object or pointer to function,
    • lvalue reference to object or lvalue reference to function,
    • pointer to member,
    • std::nullptr_t.

    In addition (§14.1/7):

    A non-type template-parameter shall not be declared to have floating point, class, or void type.

    As std::string is a class type, your instantiation of foo is not allowed.

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

Sidebar

Related Questions

Possible Duplicate: Comparing Strings in Cocoa Why is this code not recognising the NSString
Possible Duplicate: Which collection for storing unique strings? I am currently using a Dictionary<string,
Possible Duplicate: remove_if equivalent for std::map I have a set of strings: set <wstring>
Possible Duplicate: Enforcing spaces in string resources This is the strings.xml file I use
Possible Duplicate: How to concatenate strings of a string field in a PostgreSQL ‘group
Possible Duplicate: Enum with strings Is it possible to have string constants in enum
Possible Duplicate: Concatenating null strings in Java Please find below the code snippet String
Possible Duplicate: How do I compare strings in Java? why first comparison ( s1
Possible Duplicate: Where and why do I have to put the “template” and “typename”
Possible Duplicate: C++ invoke explicit template constructor First imagine I have a class Data

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.