Just playing around a little with C++. What I really want to do is to be able to setup a function with default values defined for an array or pointer argument. To keep thing
Your colleagues are wrong or maybe you misunderstood.
The first clue to understanding is that you cannot have an array as a function parameter in C or C++. The reasons are historical. So when you write void experimentA(char a[3] ...)
the compiler automatically converts it to a pointer, i.e. void experimentA(char* a ...)
. So the real question is why "abc"
is a suitable default value for a and { 'a', 'b', 'c' }
is not. The reason is as the compiler explains, "abc"
is an expression and { 'a', 'b', 'c' }
is not (its an initialiser). There are some places in C++ where you can use an initialiser and some where you can't. Default value for a parameter just happens to be one of the places you can't.