Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameters assignment with default values for a function

I have thread spawning function which accepts many parameters which have default values in the declaration.

int spawn( funcptr func, void arg = 0,int grp_id = 1,const charthreadname);

I want to initialize first parameter func and the last parameter thread name and remaining variables assigned their default values.

spawn( myfunc,"My Thread");

How can I do this.

like image 734
Sirish Avatar asked Feb 26 '23 12:02

Sirish


1 Answers

You can't.

Other languages support things like spawn(myfunc, , , "MyThread"), but not C++.

Instead, just overload it to your liking:

inline int spawn( funcptr func, const char*threadname) {
    return spawn(func, 0, 1, threadname);
}
like image 174
Gunslinger47 Avatar answered Mar 07 '23 03:03

Gunslinger47