Как выполнить неявное преобразование, передав параметр в С++ 11? [дубликат]C++

Программы на C++. Форум разработчиков
Anonymous
Как выполнить неявное преобразование, передав параметр в С++ 11? [дубликат]

Сообщение Anonymous »

Код: Выделить всё

template 
class Prop {
public:
Prop(const std::function &getter) : getter(getter) {}
Prop(const T &value) : getter([=]() { return value; }) {}
Prop(const char *value) : getter([=]() { return std::string(value); }) {}

T operator()() const {
return getter();
}

private:
const std::function getter;
};

When passed as a parameter to a non-template function, it does implicit conversion, but not when passed as a parameter to a template function.

Код: Выделить всё

void foo(const Prop &prop) {}

template 
void bar(const Prop &prop) {}

int main() {
foo(0);
bar(0); // no instance of function template "bar" matches the argument listC/C++(304)
}
Why is this happening, and how do I make it work with parameters in template functions?


Источник: https://stackoverflow.com/questions/781 ... ter-in-c11

Вернуться в «C++»