Tux*_*xer 5 c++ templates bind
我正在尝试在我的记录器类中创建一个std :: functions的向量.当我尝试将方法绑定到我的std :: function时:
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);
Run Code Online (Sandbox Code Playgroud)
add_string函数定义如下:
void add_string(string text);
Run Code Online (Sandbox Code Playgroud)
但是,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
Run Code Online (Sandbox Code Playgroud)
string绑定调用中是否缺少参数占位符?
试试这个:
bind(&NcursesWindow::add_string,&log_win,std::placeholders::_1);
Run Code Online (Sandbox Code Playgroud)
成员函数有两个参数:隐藏this指针和a std::string.您将第一个绑定到类的实例,另一个将保留,因此占位符.
| 归档时间: |
|
| 查看次数: |
864 次 |
| 最近记录: |