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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:40:00+00:00 2026-05-23T08:40:00+00:00

I currently write on an event handler system in C++0x. The handlers for each

  • 0

I currently write on an event handler system in C++0x. The “handlers” for each event (there can be multiple handlers) are registered by passing any kind of function/method that can be stored in a std::function object. This is done in C# style using the overloaded += operator. My Event-Class looks basically like this (stripped for better readability):

template<typename THandlerReturn, typename THandlerArgs...>
class Event {
    public:
        typedef THandlerReturn(HandlerSignature)(THandlerArgs...);
        typedef THandlerReturn(*HandlerFuntionPtr)(THandlerArgs...);
        typedef typename std::function<HandlerSignature> HandlerFunction;

        void operator += (HandlerFunction handler) {
            _handlers.push_back(handler);
        }

        // Some other methods for calling all handlers, ctors, etc.

    private:
        std::vector<HandlerFunction> _handlers;
};

Now I have another internal method for retrieving the actual function pointer from the std::function objects stored in the vector. It basically tries to do something like this:

// Preceeding: Get an iterator 'it' from the vector
HandlerFunctionPtr pt2func = it->target<HandlerSignature>();

At this point, when I use the Event class in my application, the compilation failes. Using a GCC 4.7 build I get the following error messages for the line above:

error: expected primary-expression before '>' token
error: expected primary-expression before ')' token

I’ve tested a little bit with the target<>() Method and the following works perfectly, assuming that the return type is void and there’s one argument of type int:

typedef void(Signature)(int);
typedef void(*FunctionPtr)(int);
std::function<Signature> func;
FunctionPtr pt2func = func.target<Signature>();

But as soon as there is one template argument involved, I get the above posted errors:

typedef THandlerReturn(Signature)(int);
typedef THandlerReturn(*FunctionPtr)(void);
std::function<Signature> func;
FunctionPtr pt2func = func.target<Signature>();

Can anyone tell me why that actually is, and if yes, if there’s any way to make it work? Any help and insights are very appreciated! Thanks in advance!

  • 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-23T08:40:01+00:00Added an answer on May 23, 2026 at 8:40 am

    You need to use template keyword as:

    HandlerFunctionPtr pt2func = it->template target<HandlerSignature>();
    

    Its because you’re calling a function template on an object whose type depends on a template argument. In the absence of the keyword template, the compiler is going to parse your code as,

    HandlerFunctionPtr pt2func = ( (it->target) < HandlerSignature ) >();
    

    which makes absolutely no sense. Hence the error.


    To know this in detail as to why template is needed, read this excellent explanation by @Johannes Schaub:

    • Where and why do I have to put the "template" and "typename" keywords?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to write an addin for PowerPoint that whenever any PowerPoint
How to config EventLogAppender for write only events from my app. Because, currently I
I want to read and write from serial using events/interrupts. Currently, I have it
I am currently trying to write functional tests for a charging form which gets
I'm currently tempted to write the following: public class Class1() { public Class1() {
Currently I'm trying to write my first Python library and I've encountered the following
currently I am trying to write to an 20x4 LCD Dot-Matrix Module using Perle's
Currently I have to write the following to update an element already contained in
I'm currently on my way to write a web application implementing the MVC and
I'm currently using ITextSharp to write a PDF to a web browser, but 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.