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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:13:47+00:00 2026-05-16T17:13:47+00:00

Rephrased Question I found that my original question wasn’t clear enough and the repliers

  • 0

Rephrased Question

I found that my original question wasn’t clear enough and the repliers misunderstood my problem. So let me try to clarify:

Let’s say I have two classes:

struct C { void(*m_func)(C*); };
struct D { std::function<void(D*)> m_func; };

Now I want to make a generic version of the two, so I do something like this:

template<typename Func>
struct G
{
Func m_func;
};

But now I don’t know how to instantiate this class:

G<void(*)(G*)> c;  //error
G<std::function<void(G*)>> d;  //error

G<void(*)( G<void(*)(G<???>*)> *)> c;  //???
G<std::function<void( G<std::function<void(G<???>*)>> *)>> d;  //???

Original Question:

Hi,

I have a template class that can take a function pointer or a std::function object as its parameter. All is fine until that function uses a pointer of the template class in its signature:

#include <functional>

template<typename Func>
class C
{
public:
    C() {}
    Func m_func;
};

void foo()
{
    C<void(*)(C*)> c;
    C<std::function<int(C*)>> d;
}

Relevant compiler errors:

error C2955: 'C' : use of class template requires template argument list
error C3203: 'function' : unspecialized class template can't be used as a template argument for template parameter 'Func', expected a real type
error C2955: 'std::tr1::function' : use of class template requires template argument list

How do it solve this problem?

  • 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-16T17:13:48+00:00Added an answer on May 16, 2026 at 5:13 pm

    You can’t name the recursive template outside itself, but you can name it inside, as the parameter list is optional in a self-reference.

    The problem then becomes one of telling the template how to pass itself to “something.”

    template< typename T >
    struct fptr_taking_type {      // this template is essentially a function
        typedef void (*type)( T ); // from types to types, the result being
    };                             // the typedef
    
    template< typename T >
    struct stdfn_taking_type {
        typedef function< void (*)( T ) > type;
    };
    
    template< template< typename > class F >
    struct G {
        typename F< G * >::type m_func; // this declares the member variable
    };
    
    ...
    
    G< fptr_taking_type > q;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to rephrase my question, cause my last one wasn't clear to everyone.
EDIT: I rephrased the question because I have not explained well. Let's see if
EDIT: I've completed rephrased the question as I've been able to simplify my problem
Rehrasing the question - Question rephrased - I have a requirement where I need
Let me rephrase the question... Here's the scenario: As an insurance agent you are
Let me rephrase my last question, what PHP library or framework can I use
sorry for my confusing question. let me rephrase the details: $query = SELECT *
I asked a similar question yesterday, but recognize that i need to rephase it
I am looking at Ogre3D code and WildMagic code and I found that both
Sorry for posting this question again. I rephrased my question a little bit. 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.