Этот баннер — требование Роскомнадзора для исполнения 152 ФЗ.
«На сайте осуществляется обработка файлов cookie, необходимых для работы сайта, а также для анализа использования сайта и улучшения предоставляемых сервисов с использованием метрической программы Яндекс.Метрика. Продолжая использовать сайт, вы даёте согласие с использованием данных технологий».
Политика конфиденциальности
|
|
|
std::function
|
|||
|---|---|---|---|
|
#18+
Слабо понимаю что ему нужно. (пример из википедии) автор#include <iostream> #include <functional> struct A { A(int num) : num_(num){} void printNumberLetter(char c) const { std::cout << "Number: " << num_ << " Letter: " << c << std::endl; } int num_; }; int main() { // Содержит вызов метода класса. std::function<void(const A&, char)> f_printA = &A::printNumberLetter; A a(10); f_printA(a, 'A'); } Сообщения от компилятора: автор1>------ Build started: Project: Project1, Configuration: Debug Win32 ------ 1> main.cpp 1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(506): error C2664: 'void std::_Func_class<_Ret,const A &,char>::_Set(std::_Func_base<_Ret,const A &,char> *)' : cannot convert argument 1 from '_Myimpl *' to 'std::_Func_base<_Ret,const A &,char> *' 1> with 1> [ 1> _Ret=void 1> ] 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(442) : see reference to function template instantiation 'void std::_Func_class<_Ret,const A &,char>::_Do_alloc<_Myimpl,_Fret(__thiscall A::* const &)(char) const,_Alloc>(_Fty,_Alloc)' being compiled 1> with 1> [ 1> _Ret=void 1> , _Fret=void 1> , _Alloc=std::allocator<std::_Func_class<void,const A &,char>> 1> , _Fty=void (__thiscall A::* const &)(char) const 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(442) : see reference to function template instantiation 'void std::_Func_class<_Ret,const A &,char>::_Do_alloc<_Myimpl,_Fret(__thiscall A::* const &)(char) const,_Alloc>(_Fty,_Alloc)' being compiled 1> with 1> [ 1> _Ret=void 1> , _Fret=void 1> , _Alloc=std::allocator<std::_Func_class<void,const A &,char>> 1> , _Fty=void (__thiscall A::* const &)(char) const 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(442) : see reference to function template instantiation 'void std::_Func_class<_Ret,const A &,char>::_Reset_alloc<_Fret,A,char,std::allocator<std::_Func_class<_Ret,const A &,char>>>(_Fret (__thiscall A::* const )(char) const,_Alloc)' being compiled 1> with 1> [ 1> _Ret=void 1> , _Fret=void 1> , _Alloc=std::allocator<std::_Func_class<void,const A &,char>> 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(442) : see reference to function template instantiation 'void std::_Func_class<_Ret,const A &,char>::_Reset_alloc<_Fret,A,char,std::allocator<std::_Func_class<_Ret,const A &,char>>>(_Fret (__thiscall A::* const )(char) const,_Alloc)' being compiled 1> with 1> [ 1> _Ret=void 1> , _Fret=void 1> , _Alloc=std::allocator<std::_Func_class<void,const A &,char>> 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,const A &,char>::_Reset<void,A,char>(_Fret (__thiscall A::* const )(char) const)' being compiled 1> with 1> [ 1> _Ret=void 1> , _Fret=void 1> ] 1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional(671) : see reference to function template instantiation 'void std::_Func_class<_Ret,const A &,char>::_Reset<void,A,char>(_Fret (__thiscall A::* const )(char) const)' being compiled 1> with 1> [ 1> _Ret=void 1> , _Fret=void 1> ] 1> c:\users\admin\documents\visual studio 2013\projects\project1\main.cpp(13) : see reference to function template instantiation 'std::function<void (const A &,char)>::function<void(__thiscall A::* )(char) const>(_Fx &&)' being compiled 1> with 1> [ 1> _Fx=void (__thiscall A::* )(char) const 1> ] 1> c:\users\admin\documents\visual studio 2013\projects\project1\main.cpp(13) : see reference to function template instantiation 'std::function<void (const A &,char)>::function<void(__thiscall A::* )(char) const>(_Fx &&)' being compiled 1> with 1> [ 1> _Fx=void (__thiscall A::* )(char) const 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 17.04.2016, 11:01 |
|
||
|
std::function
|
|||
|---|---|---|---|
|
#18+
crimeperson, Дурной пример, если честно. Хотя и компилируется на C++14 https://ideone.com/g0wdSI Видимо, ваша стандартная библиотека не дотягивает :) По-другому обычно пишут Код: plaintext 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. Но, bind -- нужен в очень редких случаях, рекомендуется использовать лямбды. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 17.04.2016, 14:20 |
|
||
|
|

start [/forum/topic.php?fid=57&msg=39217477&tid=2018546]: |
0ms |
get settings: |
9ms |
get forum list: |
11ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
69ms |
get topic data: |
11ms |
get forum data: |
2ms |
get page messages: |
47ms |
get tp. blocked users: |
2ms |
| others: | 274ms |
| total: | 433ms |

| 0 / 0 |
