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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:02:30+00:00 2026-05-30T04:02:30+00:00

I was just over specializing std::hash for a user-defined type using: template<> struct hash<…>

  • 0

I was just over specializing std::hash for a user-defined type using:

template<>
struct hash<...> {...};

When VC10 greeted me with the warning:

warning C4099: ‘std::hash<_Kty>’: type name first seen using ‘class’
now seen using ‘struct’

and I found out that its standard library declares std::hash as class, whereas the standard (or the latest free draft I have) declares it as struct.

Well, of course I know that a struct isn’t any different from a class (except for the different default access and inheritance types). But my questions are:

  1. Does VC10 violate the standard here or is it free to exchange structs for classs in any standard library components (as long as the required access types for members stay consistent, of course)?
  2. Is it legal to specialize a template class as a struct and vice versa or does this bring problems with name resolution and the like (at least VC10 thinks it’s worth a warning).
  • 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-30T04:02:31+00:00Added an answer on May 30, 2026 at 4:02 am

    First off, here is the answer to 2. taken from 14.5.1 [temp.class] paragraph 4:

    In a redeclaration, partial specialization, explicit specialization or explicit instantiation of a class template, the class-key shall agree in kind with the original class template declaration.

    However, struct and class are referring to the same class-key according to 7.1.6.3 [dcl.type.elab] paragraph 3 last sentence:

    The class-key or enum keyword present in the elaborated-type-specifier shall agree in kind with the declaration to which the name in the elaborated-type-specifier refers. […] Thus, in any elaborated-type-specifier, the enum keyword shall be used to refer to an enumeration, the union class-key shall be used to refer to a union, and either the class or struct class-key shall be used to refer to a class declared using the class or struct class-key.

    Trying g++, clang, and EDG all agree that it is possible to specialize a template declared as struct as a class. However, clang warns about having changed from struct to class or vice versa. Based on this, the standard library is free to choose whatever keyword it sees fit for the definition. Obviously, if the compiler rejects the code as a result something is seriously broken but I’d think it is the compiler rather than the library which is at error in this case.

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

Sidebar

Related Questions

I am currently using a RadTreeView and just switched over to using Load-On-Demand (ServerSideCallback)
as a warning I have very limited experience with PHP, with just over 1
Maybe I am just over thinking this and need to write some more prototype
I had been happily coding along on a decent sized solution (just over 13k
Currently, primary keys in our system are 10 digits longs, just over the limit
Just switched over from eclipse to vs 2008 for debugging javascript, i feel more
I just moved over to the Visual Basic team here at work. What is
I just came over this syntax in some of the questions in this forum,
I've inherited a web app that I've just discovered stores over 300,000 usernames/passwords in
Just like Carl's question over here I would like to ask you (because I

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.