Suppose I have a template
template <unsigned int SIZE=512>
structure Sql
{
const char * operator()(const char* format, ...)
{
deal format string here ...
return sql;
}
private:
char sql[SIZE];
}
I have another function:
int dbSelect (const char* sql, void *outdata)
{
use sql to query database here...
}
void main()
{
dbSelect(Sql<>()(“select data from abc where column =%u”,32u),&outdata);
}
Use Sql like this is safe? Sql<>() will create a temporary object ,what is the temporary object’ life time? During the dbSelect body,the temporary object’s sql[512] is still available to access? Is still valid to access?