Код: Выделить всё
#include
int main()
{
using FP = size_t (std::string::*) (const std::string &str, size_t pos) const;
FP func;
if (true)
{
func = &std::string::find_last_not_of;
} else
{
func = &std::string::find_first_not_of;
}
}
Код: Выделить всё
FP func = true ? &std::string::find_last_not_of : &std::string::find_first_not_of;
Код: Выделить всё
$ g++ c.cpp
c.cpp: In function ‘int main()’:
c.cpp:22:18: error: address of overloaded function with no contextual type information
22 | FP f= true ? &std::string::find_last_not_of : &std::string::find_first_not_of;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c.cpp:22:51: error: address of overloaded function with no contextual type information
22 | FP f= true ? &std::string::find_last_not_of : &std::string::find_first_not_of;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Подробнее здесь: https://stackoverflow.com/questions/793 ... expression