|
|
The C++ standard library doesn't have an implicit conversion method from std::string to const char pointer, which is a good thing since std::string doesn't really wrap a pointer to a constant nul-terminated char sequence, it wraps a char array (which might be heap-allocated, if SSO doesn't kick in) along with capacity and length.
There's also the point that for libraries, you'd generally want to avoid exposing std types in your public api. If a library is built with libstdc++ (default with gcc), that means it will fail to link with another built with libcxx (default with clang), and vice versa.
On Thursday, October 6, 2022 at 1:40:12 AM UTC+3 rogertunnicl...@gmail.com wrote:
I have the following definitions:-
Fl_Input *win2_unitprice; win2_unitprice = new Fl_Input(x+50,y+200,100,20,"Unit Price..:");
and the following code:-
double z; . . string s1 = to_string(z); string s2 = s1.c_str(); // win2_unitprice->value(s1); win2_unitprice->value(s1.c_str());
If I uncomment line 3 I get the following error:- error: no matching function for call to ‘Fl_Input::value(std::__cxx11::string&)’ win2_unitprice->value(s1);
but if i look at the data I see that:- s1 holds the address of the data 0x31 0x2e 0x31 0x30 .... and s2 holds the address of the data 0x31 0x2e 0x31 0x30 ....
so why do I need to use c_str() to make this work ?? Breakpoint 1, w2_browser_Callback (w=0x7dc1b0, data="" at fV3.04.cxx.267 (gdb) x/8b &s1 0x7fffffffdc30: 0x40 0xdc 0xff 0xff 0xff 0x7f 0x00 0x00 (gdb) x/8b 0x7fffffffdc40 0x7fffffffdc40: 0x31 0x2e 0x31 0x30 0x30 0x30 0x30 0x30 (gdb) x/8b &s2 0x7fffffffdc50: 0x60 0xdc 0xff 0xff 0xff 0x7f 0x00 0x00 (gdb) x/8b 0x7fffffffdc60: 0x7fffffffdc60: 0x31 0x2e 0x31 0x30 0x30 0x30 0x30 0x30
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/805dfa9e-7bbe-4701-b493-1a366d7bd054n%40googlegroups.com.
[ Direct Link to Message ] | |
|
| |