Kiki.J.Hu
Kiki.J.Hu

Reputation: 204

How to bind member function with std::function?

I want to bind member function, but it seems failed.

Q4kDeviceSource.hh
class Q4kDeviceSource {
public:
  void videoStreamCallback(QIPCamStreamCbType streamCbType, uint32_t streamId, uint8_t *buffer, size_t bufferSize);
。。。
}

typedef std::function<void(QIPCamStreamCbType cbType, uint32_t streamId,
                        uint8_t* buffer, size_t bufferSize)>
                        StreamCallback;

Q4kDeviceSource.cpp
。。。
StreamCallback videoElementryCb = std::bind(&Q4kDeviceSource::videoStreamCallback, this,
        std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);

videoElementryCb(QIPCamStreamCbType::QIPCAM_STREAMCBTYPE_NORMAL,id,NULL,0);
。。。

build failed!

./prebuilts/ndk/9/sources/cxx-stl/gnu-libstdc++/4.8/include/functional:2463: error: undefined reference to 'std::__throw_bad_function_call()' collect2: error: ld returned 1 exit status

Upvotes: 1

Views: 241

Answers (1)

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136515

Looks like you link with gcc instead of g++.

The difference is that g++ also links in libstdc++, whereas gcc does not.

Either link with g++ or add -lstdc++ to your linker command line.

Upvotes: 1

Related Questions