I have following setup, which gives me headaches because I don’t see the problem:
ValidationModule module = ValidationModule(std::vector<FilterFlag>(0));
Settings validationSettings = Settings("Validation Settings");
validationSettings.registerFloat("test", module, &ValidationModule::setRatio, &ValidationModule::getRatio, 0.0f, 1.0f);
registerFloat takes two pointers to member functions of ValidationModule
ValidationModule.h
// constructor
ValidationModule(const std::vector<FilterFlag>& filterFlags, float ratio = 0.7f);
// getter and setter, which are passed to Settings::registerFloat
inline void setRatio(float value) { _ratio = value; }
inline float getRatio() const { return _ratio; }
Settings.h
template<class TClass>
inline void Settings::registerFloat(const std::string& name, TClass owner, void (TClass::*setter)(float), float (TClass::*getter)() const, float minValue, float maxValue)
{
CallBackToMemberSingleArg<float, TClass>* setterCallback = new CallBackToMemberSingleArg<float, TClass>(owner, setter);
CallBackToMemberReturn<float, TClass>* getterCallback = new CallBackToMemberReturn<float, TClass>(owner, getter);
// some unrelated processing
[...]
}
The compiler gives me following errors for the two constructors of CallBackToMemberSingleArg and CallBackToMemberReturn:
No matching constructor for initialization of 'CallBackToMemberSingleArg<float, ValidationModule>'
No matching constructor for initialization of 'CallBackToMemberReturn<float, ValidationModule>'
Here are the constructor declarations
Callback.h
template <typename TParam>
class CallBackSingleArg
{
public:
virtual ~CallBackSingleArg() { }
virtual void call(const TParam& p) = 0;
};
template <typename TParam, typename TClass>
class CallBackToMemberSingleArg : public CallBackSingleArg<TParam>
{
void (TClass::*function)(const TParam&);
TClass* object;
public:
CallBackToMemberSingleArg(TClass* object, void(TClass::*function)(const TParam&)) : object(object), function(function) { };
void call(const TParam& p) {
(*object.*function)(p);
}
};
template <typename TParam>
class CallBackReturn
{
public:
virtual ~CallBackReturn() { }
virtual TParam call() = 0;
};
template <typename TParam, typename TClass>
class CallBackToMemberReturn : public CallBackReturn<TParam>
{
TParam (TClass::*function)();
TClass* object;
public:
CallBackToMemberReturn(TClass* object, TParam(TClass::*function)()) : object(object), function(function) { };
TParam call() {
return (*object.*function)();
}
};
I tried to change the actual setter to void setRatio(const float& value), because CallBackToMemberSingleArg takes a const reference parameter, but that didn’t help and also the call to the constructor of CallBackToMemberReturn gives the above error, so there must be something else, which I am unable to see.
You’re passing a
TClassas first parameter toCallBackToMemberSingleArgconstructor, but aTClass*is expected.