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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:41:02+00:00 2026-05-12T00:41:02+00:00

How can I get this to compile? The error is when I start using

  • 0

How can I get this to compile? The error is when I start using boost::ref(). I thought boost::ref is used to pass reference to C++ algorithm classes?

  list<Object> lst;
  lst.push_back(Object(1,2.0f));
  lst.push_back(Object(3,4.3f));

  struct between_1_and_10
  {
    int d;
    void operator() (Object& value) 
    { 
      value.a += 5; value.b -= 3.3f; 
      cout << d << endl;
      d += value.a;
    }
  };

  between_1_and_10 val;
  val.d = 4;
  for_each(lst.begin(), lst.end(), boost::ref(val));   // Problem is here
  printf("rg");

EDIT Here’s the compiler error as people suggested:

1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\algorithm(29) : error C2064: term does not evaluate to a function taking 1 arguments
1>        c:\users\swangrun\desktop\minescout work\feat-000-gettargetimages\minescouttest\maintest.cpp(102) : see reference to function template instantiation '_Fn1 std::for_each<std::list<_Ty>::_Iterator<_Secure_validation>,boost::reference_wrapper<T>>(_InIt,_InIt,_Fn1)' being compiled
1>        with
1>        [
1>            _Fn1=boost::reference_wrapper<main::between_1_and_10>,
1>            _Ty=Object,
1>            _Secure_validation=true,
1>            T=main::between_1_and_10,
1>            _InIt=std::list<Object>::_Iterator<true>
1>        ]
  • 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-12T00:41:03+00:00Added an answer on May 12, 2026 at 12:41 am

    This what you really want:

    for_each(lst.begin(), lst.end(), boost::bind<void>(boost::ref(val),_1  ) );
    

    EDIT: Some explanation upon the OP’s request. Recall that for_each() takes a function, but you were merely passing it a reference to your struct (yes, the struct has it’s operator() overloaded but you were not passing that).
    bind() basically “exposes” the function inside your struct.

    EDIT2: Explanation of the “_1” can be found in the comments below.

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

Sidebar

Ask A Question

Stats

  • Questions 161k
  • Answers 161k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I do not have this problem. Most likely the WindowActivated… May 12, 2026 at 11:45 am
  • Editorial Team
    Editorial Team added an answer Check this post which if nothing else will point you… May 12, 2026 at 11:45 am
  • Editorial Team
    Editorial Team added an answer self.canvas.coords(name) return a map object, and as the error states… May 12, 2026 at 11:45 am

Related Questions

I have a base class that has an abstract getType() method. I want subclasses
I'm using the latest release of IKVM to compile a Java .jar file into
So I have this very simply SDL application I want to be able to
I have a public ref class Test inside this class, I have: int frameWidth;

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.