Why this line doesn't compile:
function<const int&(const int&, const int&)> min_ptr = min<int>;
But this works fine:
const int &(*min_ptr)(const int&, const int&) = min<int>;
It would seem that function class is flexible and comfortable replacement for function pointers. But why this case doesn't work?
EDIT. My code:
#include <functional>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
const int&(*min_ptr)(const int&, const int&) = min<int>; //It is works fine
function<const int&(const int &, const int&)> min_f = min<int>;// Doesn't compile
/*
Error message:
error: conversion from ‘<unresolved overloaded function type>’ to non-scalar type
‘std::function<const int&(const int&, const int&)>’ requested function<const int&(const int &, const int&)> min_f = min<int>;
*/
return 0;
}
Aucun commentaire:
Enregistrer un commentaire