क्यों इस लाइन संकलित करता है नहीं:कार्यात्मक सी ++ 11 अजीब व्यवहार
function<const int&(const int&, const int&)> min_ptr = min<int>;
लेकिन यह ठीक काम करता है:
const int &(*min_ptr)(const int&, const int&) = min<int>;
यह प्रतीत होता है कि समारोह वर्ग समारोह के लिए लचीला और आरामदायक प्रतिस्थापन है संकेत दिए गए। लेकिन यह मामला क्यों काम नहीं करता है?
संपादित करें। मेरे कोड:
#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;
}
जीसीसी संस्करण 4.8.2, --std = C++ 11
असली कार्यक्रम कृपया, और वास्तविक त्रुटि संदेश। 'Std ::' गायब होने जितना आसान हो सकता है। – MSalters
वास्तव में, यह मेरे लिए नामस्थान std; ' –
कंपाइलर, संस्करण और झंडे का उपयोग कर संकलित करता है? – Yakk