Reference to static member function & inheritance

I'm using libuv in a C++ program. I have two classes, A and B that inherit from C.

I use libuv and declared an instance of uv_signal_t on C. Creating an instance of uv_signal_t requires a callback to be passed. I can easily pass a lambda to the C function to go around the problem of references to static member functions:

const int32_t r = uv_signal_start(&this->signal, [](uv_signal_t *handle, int signum){}, SIGABRT);

But how can I provide a different implementation of the callback on each child class? Ideally I'd have some common code implemented on C.cpp and additional code on each child.


To be clear, I cannot change the signature of the callback method, as it's defined by libuv. I could edit the source for libuv, but I'm not sure I want to go that deep.


I'll add a function pointer as a property to my class C and implement it as necessary on the derived classes. More here.

I think you can capture this pointer in the lambda, and call a virtual function through this. The virtual function can be overrided in derived classes then.

 const int32_t r = uv_signal_start(&this->signal, [this](uv_signal_t *handle, int signum){ return this->callback(); }, SIGABRT);

Need Your Help

Download a file to PC using wget command

ubuntu cloud wget remote-server downloadfile

I want to download a file from a cloud server to my PC using wget command in ubuntu. Following is what I executed in terminal.

Cloudflare .htaccess “raw access log”?

.htaccess cloudflare

My raw access log is now filled with Cloudflare IP addresses!

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.