How to initialize "unsigned char *" with default argument in C++?

c++, default-arguments, initialization

Solution

You say that this is a "prefix" argument to apply to the printing.

The answer is that you should make the argument `const`, stop doing whatever mutations you're doing to it inside the function, and then use `""` as a default argument:

void print(const char* prefix = "")

Problem

I have a class with a method with the following signature: ``` void print(unsigned char *word); ``` I need to set `""` as default value for `word`, how can I do that? I tried the obvious `void print(unsigned char *word="");` but I got the following error: ``` error: cannot initialize a parameter of type 'unsigned char *' with an lvalue of type 'const char [1]' void print(unsigned char *word=""); ``` Since I can't initialize `word` with a string literal who should I do it?

Original source