This is how I have my code setup:
class SomeClass
{
public:
std::function<void()> someFunction;
}
AnotherClass.h
class AnotherClass
{
public:
void anotherFunction();
void yetAnotherFunction();
SomeClass someClass;
}
AnotherClass.cpp
void AnotherClass::anotherFunction()
{
std::cout << "triggerd" << std::endl;
}
void AnotherClass::yetAnotherFunction()
{
someClass.someFunction = &AnotherClass::anotherFunction; //here
}
This resulted in a compile time error: error C2664: 'std::_Func_class<_Ret>::_Set' : cannot convert parameter 1 from '_Myimpl *' to 'std::_Func_base<_Rx> *'
After some research I found that this is a bug from VS2012 (source). So I changed the line labeled "here" to someClass.someFunction = std::mem_fn(&AnotherClass::anotherFunction);
just like the solution says in the link. However, now this results in another compile time error: error C2562: 'std::_Callable_obj<_Ty>::_ApplyX' : 'void' function returning a value
. So from the research I've found on that error, it means that there is a function declared as void returning a value. This is where I'm stuck because I'm 100% sure I don't have any functions returning a value that shouldn't be plus I didn't get this error before changing the line labeled "here". I not sure if this is another bug in VS2012 but the error does say: std::_Callable_obj<_Ty>::_ApplyX
which is obviously not my function.
Does anybody have any information on why this is happening and how I can resolve it?
Thanks.