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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:13:37+00:00 2026-06-07T15:13:37+00:00

This is a functor: class add_x { int x; public: add_x(int x) : x(x)

  • 0

This is a functor:

class add_x {

 int x;

public:
  add_x(int x) : x(x) {}
  int operator()(int y) { return x + y; }

};

And from main I can do this:

add_x add10(10); // create my functor 
int i = add10(20); // add 20 and return it 

How can I combine the functor with typedef?

For instance, I came across this:

typedef int (*myfuncType)(float f, char c1,char c2);
myfuncType pt2Function = NULL; 

But what am I defining here exactly? operator ()?

  • 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-07T15:13:39+00:00Added an answer on June 7, 2026 at 3:13 pm

    Function pointer is – as its name says – just a pointer to function. You cannot use a pointer to function to point to functor, which is essentially a class with overloaded () operator.

    You may be interested in std::function from C++11:

    #include <functional>
    
    (...)
    std::function<int(int)> fn = add_x(10);
    int i = fn(20);
    

    Edit: Ok, I see, what you are asking for.

    Maybe some code will make things clear.

    int fn(float a, char b, char c) { ... }
    
    (...)
    
    typedef int (*myFuncType)(float f, char c1, char c2);
    
    myFuncType ptrToFun = &fn;
    
    (*fn)(1.0f, 'a', 'z');
    

    This typedef creates a “pointer-to-function” type. If you declare a variable of this type, then you’ll be able to assign to it a pointer to function (extracted with regular & operator) and – for example – pass to another function or just store (or call this function).

    std::function is a lot more flexible, because you can store in it a pointer to function, a functor or even a lambda and call them normally.

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

Sidebar

Related Questions

I'm trying to create a thread class that executes a functor from an adapter.
I have the following functor: class ComparatorClass { public: bool operator () (SimulatedDiskFile *
I'd like to have functor class like this: public class Functor<T, R> { public
If I have a functor like this... class DoStuff { private: std::vector < int
I have this functor: struct functor { template<class T> void operator()(T value) // (*)
Possible Duplicate: pthread Function from a Class I have this code that I can't
Given the following code from a Microsoft example: public class EngineMeasurementCollection : Collection<EngineMeasurement> {
Look at this template: template <class T> auto checkErrorCode(T& functor) -> decltype(functor()) { auto
The STL functors are implemented like this: template<class T> struct less{ bool operator()(T const&
Can lambda expressions be used as class template parameters? (Note this is a very

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.