Can someone please explain these weird compile errors I get for this code?
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xrefwrap(283): error : expression preceding parentheses of apparent call must have (pointer-to-) function type
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional(1148): error : no instance of overloaded function "std::_Pmd_wrap<_Pmd_t, _Rx, _Farg0>::operator() [with _Pmd_t=int (inputLoader::*)(), _Rx=int (), _Farg0=inputLoader]" matches the argument list
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xrefwrap(283): error : return value type does not match the function type
It obviously has something to do with the way I am using that function<T()> template but other than that I can't see it.
#include <functional>
using std::function;
using std::bind;
template <typename T>
class memoizedProperty {
bool _calculated = false;
T* _valuePtr = NULL;
function<T()> _definition = NULL;
public:
operator T() const {
if (_calculated) return *_valuePtr;
if (!_definition) return T(0);
*_valuePtr = _definition();
_calculated = true;
return *_valuePtr;
}
memoizedProperty(T* valuePtr, function<T()> definition) {
_valuePtr = valuePtr;
_definition = definition;
}
};
class inputLoader {
inforceRecord* _record;
policyInput* _input;
int _WBFlag() {
return _record->PdLB_WBFlag;
}
public:
memoizedProperty<int> WBFlag;
inputLoader(inforceRecord* record, policyInput* input) :
_record(record), _input(input),
WBFlag(&input->WBFlag, bind(&inputLoader::_WBFlag, this))
{ }
};
Aucun commentaire:
Enregistrer un commentaire