Emulating std::bind in C

前端 未结 4 1758
北荒
北荒 2021-01-12 16:43

I\'m using std::bind to provide a callback while abstracting some logic by binding some parameters first. i.e.

void start() {

    int secret_id = 43534;

           


        
4条回答
  •  Happy的楠姐
    2021-01-12 17:34

    The short answer is no.

    The only thing you can do is declare another function that has the secret_id built into it. If you're using C99 or newer you can make it an inline function to at least limit the function call overhead, although a newer compiler may do that by itself anyway.

    To be frank though, that is all std::bind is doing, as it is returning a templated struct, std::bind simply declares a new functor that has secret_id built into it.

提交回复
热议问题