vendredi 21 juillet 2017

Best way to zero all the elements of the struct

I have a struct that I frequently use in my code which is :

struct HttpResponse{

string header;
string response;
int statusCode;

HttpResponse():header(""),response(""),statusCode(0){}
HttpResponse(string header,string response,int statusCode):header(header),response(response),statusCode(statusCode){}};

I need to make sure that all the strings are initialized to "" and the integer to (0) . Creating the struct each time I need it with default constructor or creating it once and zero all its members after each use are the options that I can see . Which approach would be more efficient ?

Aucun commentaire:

Enregistrer un commentaire