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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:00:43+00:00 2026-06-18T06:00:43+00:00

The following code is a simplified minimal version of a feature I am trying

  • 0

The following code is a simplified minimal version of a feature I am trying to implement for a client requirement.

It fails to compile on IBM’s XLC compiler (version 9 and 11, both) with the error A non-type template parameter cannot have type "int X::*".. However, I have tried the same code with g++ 4.7.2, clang++ 3.2 and Intel-13.0, and they compile it successfully.

I am curious to know if XLC is the only sane voice here, or are the other compilers correct?

struct X {
    X() : y(123) {}
    int y;
};

struct XFoo {
   typedef int X::* Type;
};

template <typename Name, typename Name::Type value>
struct Bar {
    typename Name::Type getValue(Name) {
        return value;
    }
};

template class Bar<XFoo, &X::y>;    // xlc error here, works fine on others

int main() {}

I read through the C++ 2003 standard chapter on templates several times, and could not conclusively find something which prohibits using <type> <class>::* as a non-template type. I have already searched through SO and search engines for an explanation, but have not come across any authoritative source which helps me decide.

I understand that this may not be a good coding practice, but this is required for the client code since their requirement is somewhat unique. I have also tried out various other alternatives but it does not work for them.

  • 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-18T06:00:45+00:00Added an answer on June 18, 2026 at 6:00 am

    § 14.1/4 of the C++03 Standard allows having pointers to member as a template parameter:

    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,
    • reference to object or reference to function,
    • pointer to member.

    Correspondingly, per § 14.3.2/1:

    A template-argument for a non-type, non-template template-parameter shall be one of:

    • an integral constant-expression of integral or enumeration type; or
    • the name of a non-type template-parameter; or
    • the address of an object or function with external linkage, including function templates and function template-ids but excluding non-static class members, expressed as & id-expression where the & is optional if the name refers to a function or array, or if the corresponding template-parameter is a reference; or
    • a pointer to member expressed as described in 5.3.1.

    Thus, non-type template parameters can be pointers to member. There are some limitations which apply to template specialization, but they don’t seem to apply in this case.

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

Sidebar

Related Questions

When trying to compile the following (simplified) code for multiple platforms, I found that
Following code is simplified version of the code that I am trying to optimize.
The following code is a simplified version of what I use for event dispatching.
The following code (simplified example, that triggers the error) doesn't compile with VS 2008:
The following code is the simplified version of my problem: public partial class Form1
I have the following C++ code (simplified version): class Shape { bool isCircle =
If I have the following code (simplified version of the problem): class TestA {
The following code is a simplified example of what I'm trying to understand. I'm
Please check the following section of code (Simplified version) my concern is in the
Imagine I have the following code (simplified regarding my real context of course): <div

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.