Public Group

# std::mem_fun, can't deduce template argument

This topic is 3910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Here is the code:
class CTest
{
std::list<int> List;

public:
bool __stdcall Functor(int A)
{
//Do some stuff
return true;
};

void __stdcall Excute
{
std::for_each(List.begin(), List.end(),
std::bind1st(std::mem_fun(&CTest::Functor), this));
};
};


When compiling, it gives an error: could not deduce template argument for '_Result (__thiscall _Ty::* )(_Arg) const' from 'bool (__stdcall CTest::* )(int)'

##### Share on other sites
If you read the error it says it cannot perform a conversion between types, and if you look closely at the flagged types they differ only in calling convention. Namely __thiscall and __stdcall. It seems that calling convention plays a part in a functions type.

If you don't specify the calling convention that will make the error go away (there should be no reason for you to explicitly choose it anyways).

##### Share on other sites
Why on in the name of all that is holy are you trying to specify __stdcall calling convention explicitly? Member functions - the ones you define inside a class which are not static - are supposed to be __thiscall. Hint: it's named after the keyword "this". You know, the bit you want to pass to std::bind1st.

It looks like you've mixed up two attempts at fixing the same problem, one of which is correct (setting up std::bind1st and std::mem_fun logic) and one of which is an ungodly WTF (trying to force a calling convention that doesn't actually work for those functions).

By the way, why does Functor return anything?

1. 1
2. 2
3. 3
4. 4
frob
12
5. 5

• 16
• 13
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632172
• Total Posts
3004561

×