c++ - getters and setters in class -


i trying write program considering have huge array of objects( conatinng data such id, name etc) have display menu :

1)

display_menu() {     vector< cd > cdarray;     //some statements display     switch(choice)     {         //case1 , case 2, ...         case x;             for(int i=0; < cdarray.size(); i++)                 cdarray[i].printcd(); //printcd() method of class cd         //default     } } 

but lead lot of function call overhead if vector/array large making slow.

2) shall delare function printcd() inline or

3) declare object call function , pass vector/array reference :

display_menu() {     vector< cd > cdarray;      cd obj;      //some statements display     switch(choice)     {         //case1 , case 2, ...         case x;             obj.printcd(cdarray); //cdarray passed reference         //default     } } 

is there wrong third approach

what approach suggest?

you're on analyzing problem. make readable first, worry performance. 99 times out of 100 think greatest source of performance bottlenecks wrong.

edit:

to answer question, i'd think in terms of object oriented design. cd object need know how print screen? need know ostreams in general? think answer no. best way sort of thing in c++ either have helper function overloads << operator works ostreams without forcing knowledge of stream object being used or have method returns string representation of object don't need worry string going.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -