How can I properly pass a const string, for example: "Hello" as a default parameter to a constructor without getting any warnings and errors? In other words how can I preserve memory for them before the function is called?
#include <iostream>
const char *defString = "Hello";
void foo(const char *str = defString) {
std::cout << str;
}
int main() {
foo();
foo("Hello, world!\n");
}