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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:39:16+00:00 2026-06-09T19:39:16+00:00

#include <iostream> #include <boost/bind.hpp> struct FCall3Templ { template<typename ARG1, typename ARG2> ARG1 operator()(ARG1 arg1,

  • 0
#include <iostream> 
#include <boost/bind.hpp>

struct FCall3Templ {

  template<typename ARG1, typename ARG2>
  ARG1 operator()(ARG1 arg1, ARG2 arg2) {
    return arg1+arg2;
  }
};
int main() {
  boost::bind<int>(FCall3Templ(), 45, 56)(); // call 1
  boost::bind<double>(FCall3Templ(), 45.0, 56.0)(); // call 2
  return 0;
}

I’m posting the same code that you can find here .

I’m relatively new to meta-programming, boost::bind and operator overloading, but i don’t get get what this code does in some portion of the code and i have this questions:

  • why using operator() without specifying the label for that operator? What is overloading/defining?
  • how i’m supposed to catch and store the value returned by the 2 calls using an assignment with T var = ? ?
  • what does it mean the fact that the last () is empty in both calls ? Is the call for the operator? So what is the name for this technique/operator?
  • why using the operator overloading this way and not using just a method?

Thanks.

  • 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-09T19:39:18+00:00Added an answer on June 9, 2026 at 7:39 pm

    Taking your questions in turn:

    1) operator() is the () operator for an object. For example, if you look at the definition for std::less, it defines operator() to take two arguments and do a comparison, and return the result. This allows you to write

      bool foo(int a, int b)
        {
           std::less<int> compare;
           return compare(int a, int b);
        }
    

    2) In this case, you could catch them like you normally would.

    int i = boost::bind<int>(FCall3Templ(), 45, 56)(); // call 1     
    double d = boost::bind<double>(FCall3Templ(), 45.0, 56.0)(); // call 2    
    

    3) boost::bind is used to take a function-object (an object with operator() defined), function pointer, or member function pointer optionally along with arguments and returns a new function object (type of which is difficult to describe) that when invoked uses the bound arguments (and possible arguments during the invoke). See the documentation for boost::bind

    In this case, the answer is simply calling boost::bind and then immediatly invoking the result. The second set of () are invoking the result. Since all of the arguments were bound at the time boost::bind was called, no additional arguments were necessary.

    4) And the reason why was that the original question was asking how to make boost::bind choose the correct function template instantiation automatically. Unfortunately, when using function pointers (including template functions), boost::bind cannot perform overload resolution automatically, since it has to be passed a single function pointer as it’s first argument, and it is not aware of the how to perform the overload resolution.

    However, if given a single functor, and that function defines a templated member function operator() or even an overloaded operator (), it can perform the overload resolution when it is invoked.

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

Sidebar

Related Questions

#include <iostream> #include <algorithm> #include <vector> #include <boost/array.hpp> #include <boost/bind.hpp> int main() { boost::array<int,
Consider the following code: #include <iostream> #include <vector> #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/io.hpp> int main()
Consider following example. #include <iostream> #include <algorithm> #include <vector> #include <boost/bind.hpp> void func(int e,
Consider the following program: #include <iostream> #include boost/filesystem.hpp int main() { boost::filesystem::directory_entry d(test.txt); boost::filesystem::directory_entry
Example: #include <iostream> #include <boost/call_traits.hpp> #include <type_traits> boost::call_traits<int>::param_type f() { return 1; } int
#include <boost/ptr_container/ptr_vector.hpp> #include <iostream> using namespace std; using namespace boost; struct A { ~A()
#include <boost/bind.hpp> #include <iostream> using namespace std; using boost::bind; class A { public: void
#include <cstdlib> #include <iostream> #include <boost/bind.hpp> #include <boost/asio.hpp> using boost::asio::ip::tcp; class session { public:
Compiling this example #include <boost/bind.hpp> #include <boost/algorithm/string.hpp> #include <algorithm> #include <iostream> #include <vector> using
Consider following example: #include <iostream> #include <functional> #include <algorithm> #include <vector> #include <boost/bind.hpp> const

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.