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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:59:00+00:00 2026-05-14T02:59:00+00:00

The following code yields an error error: ‘struct Foo’ is not a valid type

  • 0

The following code yields an error error: ‘struct Foo’ is not a valid type for a template constant parameter:

template <struct Foo>
struct Bar {

};

Why is that so?

template <class Foo>
struct Bar {

};

works perfectly fine and even accepts an struct as argument.

  • 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-14T02:59:00+00:00Added an answer on May 14, 2026 at 2:59 am

    This is just an artifact of the syntax rules – the syntax just lets you use the class or typename keywords to indicate a type template parameter. Otherwise the parameter has to be a ‘non-type’ template parameter (basically an integral, pointer or reference type).

    I suppose Stroustrup (and whoever else he might have taken input from) decided that there was no need to include struct as a a keyword to indicate a type template parameter since there was no need for backwards compatibility with C.

    In fact, my recollection (I’ll have to do some book readin’ when I get back home) is that when typename was added to indicate a template type parameter, Stroustrup would have liked to take away using the class keyword for that purpose (since it was confusing), but there was too much code that relied on it.


    Edit:

    Turns out the story is more like (from a blog entry by Stan Lippman):

    The reason for the two keywords is
    historical. In the original template
    specification, Stroustrup reused the
    existing class keyword to specify a
    type parameter rather than introduce a
    new keyword that might of course break
    existing programs. It wasn’t that a
    new keyword wasn’t considered — just
    that it wasn’t considered necessary
    given its potential disruption. And up
    until the ISO-C++ standard, this was
    the only way to declare a type
    parameter.

    Reuses of existing keywords seems to
    always sow confusion. What we found is
    that beginners were [wondering]
    whether the use of the class
    constrained or limited the type
    arguments a user could specify to be
    class types rather than, say, a
    built-in or pointer type. So, there
    was some feeling that not having
    introduced a new keyword was a
    mistake.

    During standardization, certain
    constructs were discovered within a
    template definition that resolved to
    expressions although they were meant
    to indicate declarations

    …

    The committee decided that a new
    keyword was just the ticket to get the
    compiler off its unfortunate obsession
    with expressions. The new keyword was
    the self-describing typename.

    …

    Since the keyword was on the payroll,
    heck, why not fix the confusion caused
    by the original decision to reuse the
    class keyword. Of course, given the
    extensive body of existing code and
    books and articles and talks and
    postings using the class keyword, they
    chose to also retain support for that
    use of the keyword as well. So that’s
    why you have both.

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

Sidebar

Related Questions

The following code: template <typename S, typename T> struct foo { void bar(); };
The execution of the following code yields error :No overloads of ProcessPerson Matches ThreadStart.
Consider the following piece of code: class foo { private function m() { echo
The following code works great in IE, but not in FF or Safari. I
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
Can you help? The following code: class MT { public: static int ms_number; };
Running the following C# code through NUnit yields Test.ControllerTest.TestSanity: Expected: `<System.DivideByZeroException>` But was: null
Since a short time my rails applications yields the following runtime error in the
I have the following code: class Program { static void Main(string[] args) { string
Say we've got the following two classes: abstract class Foo { public abstract function

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.