I have a method / function:
void foo() {
static const std::string strSQLQuery = "SELECT ... ";
const std::string strSQLQuery = "SELECT ... ";
const std::string strSQL = strSQLQuery + strWHERE;
doSthOnDataBase(strSQL);
}
(SQL is just an example)
static const It will be initialized only once, but it is stored in memory until the process is completed.constwill be initialized every time it is executed foo(), but the memory (stack) is freed when the block is completed {}.
On the other hand, the string "SELECT ... "must still be hard-coded in the program code. And that doesn’t matter if we use 1. or 2.
So which approach is better? Using static const std::stringor just const std::string?
, , , , foo() - 1000 ( ) 1000 ( ).
( static const char * const char * qaru.site/questions/364264/..., const char*.)