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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:43:55+00:00 2026-05-27T01:43:55+00:00

First time I use templates and pointer to member functions at the same time

  • 0

First time I use templates and pointer to member functions at the same time and I stumbled across following problem.

I declared a struct Proxy for a typedef, since templates and typedefs are not working together (I know this should be possible in C++11, MSVC++ does not accept it though). Now I want to declare a templated(!) function which uses the proxy with the templates type. This is what causes the error at compilation. Please have a look at the (simplified) code below, I added some examples to clarify the problem.

I am working with standard VC++ 2010 (no CLR/CLI).

template<typename T>
struct Proxy
{
    typedef bool (CClass::*MethodPtr)(const T* const objectX);
}

class CClass
{
    // warning: dependent name is not a type
    // error:: Method can not be a template definition
    template<typename T>
    bool Method( Proxy<T>::MethodPtr );

    // this works, but i want to specify T instead of int of course
    template<typename t>
    bool method( Proxy<int>::MethodPtr );

    // this is what i use
    template<typename T>
    bool Method( bool (CClass::*MethodPtr)(const T* const objectX) );
}

template<typename T>
bool CClass::Method( bool (CClass::*MethodPtr)(const T* const objectX) ) 
{
    // next line compiles without problems
    Proxy<T>::MethodPtr ptr2;
}
  • 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-27T01:43:56+00:00Added an answer on May 27, 2026 at 1:43 am

    You need to use typename to indicate where a dependent name is a type; in particular, the first declaration of Method should be:

    template<typename T>
    bool Method( typename Proxy<T>::MethodPtr );
    

    and the line that you say compiles without problems (but only because VC++ has an “extension” that accepts ill-formed code) should be:

    // next line compiles without problems
    typename Proxy<T>::MethodPtr ptr2;
    

    You’re also missing semicolons after the class definitions, and a forward declaration of CClass before the definition of Proxy.

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

Sidebar

Related Questions

first time use JTree. Just wondering is it possible to have more than one
this is my first time trying to use document classes in AS3 and im
First time I've come to use collection_select in a project and I've hit a
use this website a lot but first time posting. My program creates a number
I am preparing to use continuous integration for the first time. I will be
I'm trying to use an event listener for the first time. All samples I've
I am tryign to use Doctrine_Pager for the first time. So I have the
When i use RequiredFieldValidator for Validation FCKEditor , The first time that the form
I'm using BackgroundWorker for the first time, and use is not entirely clear. Can
I am trying to use multimap for the first time but my app will

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.