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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:17:53+00:00 2026-05-29T17:17:53+00:00

As one of the class template parameters I need to use a pointer to

  • 0

As one of the class template parameters I need to use a pointer to member:

template <class Base, typename Member, Member Base::*m>
class MemPtrTestUgly
{
...
};

This needs to be used as

struct S
{
    int t;
}

MembPtrTestUgly <S, int, &S::t> m;

But I want to use it as this:

MemPtrTestNice<S, &S::t> m;

The member type is deduced from the member pointer. I cannot use function template, as the MemPtrTest class is not supposed to be instantiated (there are just some static functions that will be used). Is there a way how to do it in pure C++03 (no Boost or TR1)?

  • 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-29T17:17:55+00:00Added an answer on May 29, 2026 at 5:17 pm

    You can use partial specialization and get a pretty nice-looking implementation:

    template <typename TMember, TMember MemberPtr>
    class MemPtrTest;
    
    template <typename TBase, typename TType, TType TBase::*MemberPtr>
    class MemPtrTest<TType TBase::*, MemberPtr>
    {
        // ...
    };
    

    This would be used as:

    MemPtrTest<decltype(&S::t), &S::t> m;
    

    Of course, this requires decltype or an equivalent, if you don’t want to implicitly specify the member type.

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

Sidebar

Related Questions

Given a class with a member template function like this one: template <typename t>
Can lambda expressions be used as class template parameters? (Note this is a very
To specialize a class template, one has to redefine all of the member functions
Possible Duplicate: What is the difference between "typename" and "class" template parameters? When defining
I have a class expecting a two parameters template, like this: template<template <class, class>
My code is similar to the one given in this thread . template<class T>
Problem Consider the following class template <typename T> struct A { T x; };
I used to have one class for one file. For example car.cs has the
I have one class that needs to grab an attribute that is set in
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name

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.