Jump to content
  • Advertisement
Sign in to follow this  
littlekid

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.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!