c++中stdbind在带有参数(字符串)的函数中的用法
usage of std bind in c++ for functions with an argument (string)
我正试图在记录器类中创建一个std::函数向量。当我试图将一个方法绑定到我的std::函数时,比如:
NcursesWindow log_win("Logs",LINES-1,COLS/3,0,COLS*2/3);
std::function<void(std::string)> f = std::bind(&NcursesWindow::add_string,&log_win);
add_string函数的定义如下:
void add_string(string text);
然而,gcc(使用gfilt插件来尝试理解模板错误)返回:
BD Software STL Message Decryptor v3.10 for gcc 2/3/4
In file included from ./inc/ncursesui.h:6:0,
from src/ncursesui.cpp:1:
functional: In static member function ‘static void _Function_handler<
void({basic_string<char>} ...), _Bind<
_Mem_fn<void (NcursesWindow::*)(basic_string<char>)>(
NcursesWindow)>
>::_M_invoke(const _Any_data &, {basic_string<char>} ...)’:
[STL Decryptor: Suppressed 1 more STL standard header message]
src/ncursesui.cpp:32:86: instantiated from here
functional:1778:2: erreur: no match for call to ‘(
_Bind<
_Mem_fn<void (NcursesWindow::*)(basic_string<char>)>(
NcursesWindow)>) (basic_string<char>)’
STL Decryptor reminders:
Use the /hdr:L option to see all suppressed standard lib headers
Use the /cand:L option to see all suppressed template candidates
绑定调用中是否缺少string
参数的占位符?
试试这个:
bind(&NcursesWindow::add_string,&log_win,std::placeholders::_1);
成员函数有两个参数:隐藏的this
指针和std::string
。您将第一个绑定到类的实例,另一个将保留,因此是占位符。
相关文章:
- 字符串函数在目标C++上运行时C++返回空
- 字符串函数返回奇怪的值
- 这里的字符串函数是什么意思
- 在字符串函数中抛出'char const*'实例后调用的终止
- 为什么 stl 字符串C++函数有时出错有时会出错?
- 从C++为字符串函数设置_ENV
- 来自 2D 数组的字符串函数
- 返回最长的公共子字符串函数 c ++
- 使用getline和字符串函数C++程序中的分段错误
- 在字符串函数的指针中返回地址
- 字符串函数:strcat()
- 这个子字符串函数有什么问题
- 字符串函数不返回字符串? C++
- 使用向量和字符串函数返回字符串
- 尝试修复一个字符串函数,该函数采用字符串并通过替换一些单词来更改它
- 逐字读取字符数组,无需字符串函数
- 我从我的字符串函数返回到主函数
- 为什么我不能从字符串函数返回字符串数组?
- 如何在不使用字符串函数的情况下在char数组中找到字符串?(C )
- 带有 #include< iostream.h> 的程序允许使用 strlen() 等字符串函数。为什么?