Boost logo

Boost Users :

Subject: [Boost-users] [Bind] Unexpected behavior when binding const char* to function
From: Piotr Jachowicz (pjachowi_at_[hidden])
Date: 2010-04-26 16:34:36


Hello,

This code proceces "xyz", contrary to user intention to bind "abc":

void echo(const char* s) {
   cout << s << '\n';
}

int main()
{
   string s("abc");
   function<void ()> f = boost::bind(echo, s.c_str());
   s = "xyz";
   f();
}

This is misleading. Changing "echo(const char*)" into "echo(string)"
produces "abc", as expected. Is there any way (other than echo
wrapper) to get "abc" as expected?

-- 
Piotr Jachowicz

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net