I've got a function which receives a char *
argument:
Foo::Foo (char * arg0) {
....
}
In the original example, a char[]
is used to pass this value...
char bar[] = "Bar";
Instance.foo (bar);
...which works fine.
But, I've found that I can pass a string literal, cast as a char *
, without any warnings from the compiler.
Instance.Foo ((char *) "Bar");
However, from my reading, it seems that should be avoided - the value of the memory that is pointed to could change.
Is the above statement true ("this should be avoided") or is this appropriate in this situation?
Edit - further research turned up this article which addresses my question pretty well...