c++ - Better cast an element of a list or use a pointer to it? -


say have struct this

struct mystruct {   int a;   int b;   string str;   [...and on...] }; 

now have pointer list of structures

list<mystruct*>* mylist; 

and need use elements in for-loop. access element in for-loop need this

((mystruct)mylist[i])->a 

in terms of performance better way (i.e. cast) or better use pointer element, i.e. declare pointer before for-loop , each time this

//before for-loop mystruct* s;  //inside for-loop for(...) {   s = mylist[i];   s->a;   ... } 

list<mystruct*>* mylist; 

since mylist pointer list of mystruct*, don't need cast. need dereference mylist before index it:

(*mylist)[i]->a 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -