Thursday 15 January 2015

c++ - Function overloading vs function variable initialization -


I want to know which codes work better under normal circumstances and if there is any relevant difference between them. .

1 case

  float x; Float echo (float a, float b, float x = x) {// a, b, work with x}}   

2 case

  float x; Float foo (float a, float b, float x) {// do stuff with A, B, x ...} float foo (float A, float B) {// do stuff with A, B, x ... }    

The default argument is a blessing and a curse; They allow you to reduce the repetition of the controllers - which can cause errors themselves

Unfortunately, they also mean that many times more diligence is required when the refactoring code, especially when you have a Only submit more and more forms of finger prints.

Few blank (integer count, void * p = nullptr, int count = 1);

is happening

  some are not cracked (integer count, bool hasPtr = true, zero * ptr = nullptr, int count = 1);   

is causing a problem where people were actually filled in all 3 arguments. SomeFunc (10, p, 0) is going to match successfully

  someFunc (/ * count = * / 10, / * hasPtr = * / true, / * ptr * / = null, / * count * / = 1)   

So remember to fix it There is additional work to do. My experience has been that other programmers often come after this kind of change and there is a rotten situation of dirty crash / behavior.

No comments:

Post a Comment