Anyone know how to create functions where you can skip parameters in the call, that dont need to be changed, something like:
I know I've seen this done but I cant figure out how to do it without getting a "parameter missed" error in the compiler.
Yes thats what I have always done, but I find myself rearranging parameters to avoid long function calls. I think it would be better if,,,, were to mean skipped parameters, use default values. After all, the compiler already knows the parameter is missing because it makes an error to say so, so why cant it just take the default if it is already initialized ?
Yes thats what I have always done, but I find myself rearranging parameters to avoid long function calls. I think it would be better if,,,, were to mean skipped parameters, use default values. After all, the compiler already knows the parameter is missing because it makes an error to say so, so why cant it just take the default if it is already initialized ?
Wouldn't it be more practical to pass zero and work it out inside the function?
You only need to do it once. Just a thought.
myfunction(1,0,0,0,5) //asuming the skipped function parameters are already intitialized ... void myfucntion(int param1=1, int param2=2, int param3=3, int param4=4, int param5=5) { int param_1=1; if(param1 != 0) param_1 = param1; }
This way is also possible:
class MyClass { public: int param1, param2, param3, param4, param5; MyClass() : param1(1), param2(2), param3(3), param4(4), param5(5) {} void myFunction() { // do something } }; void testFunction() { MyClass a; a.param5 = 1; a.param4 = 1; a.myFunction(); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Anyone know how to create functions where you can skip parameters in the call, that dont need to be changed, something like:
I know I've seen this done but I cant figure out how to do it without getting a "parameter missed" error in the compiler.