1/25/2009

Default Argument

When I write define of function or method with C++, I always write next code.

namespace my{
enum Type{
NONE = 0x00,
SCALAR = 0x01,
VECTOR = 0x03,
};
void function(double* , Type type = NONE);
}


I want that user of my function understand the function more easily than next code.


namespace my{
enum Type{
NONE = 0x00,
SCALAR = 0x01,
VECTOR = 0x03,
};
void function(double* , Type type);
void function(double*);
}


Above code is the same as before function used default argument.

Using Default argument, Code line decreases.

No comments: