Sign in to follow this  

std::mem_fun, can't deduce template argument

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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?

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this