Default Parameter Support?


#1

I can’t find any description of default parameters. I’ve found with constructors you can easily supply:

template <class T = PointPrecision>
class Size{
public:
	Size():width(0), height(0), depth(0){}
        //Notice the default value for a_depth.
	Size(T a_width, T a_height, T a_depth = 0):width(a_width),height(a_height),depth(a_depth){}
//OTHER IMPLEMENTATION STUFF HERE
}

	a_script.add(chaiscript::user_type<Size<T>>(), "Size" + a_postfix);
	a_script.add(chaiscript::constructor<Size<T>()>(), "Size" + a_postfix);
	a_script.add(chaiscript::constructor<Size<T>(T, T, T)>(), "Size" + a_postfix);
	a_script.add(chaiscript::constructor<Size<T>(T, T)>(), "Size" + a_postfix); //support defautl parameter here...

Now for a regular function, can you support default parameters in a direct way with a member function pointer or do I need a lambda?


#2

Lambda is the easiest method, otherwise you come down to the whole casting-of-function-pointers thing. There’s no way else that C++ will allow, that I know of. I’d be happy to be corrected on that.