Thursday, December 24, 2009

Can somebody give me real life scenarios in programming?

Where I would need to do the following?





Use bit fields in a struct.


Use a smart pointer.


Use bit masking.


Use a function pointer.





Language: c++Can somebody give me real life scenarios in programming?
a bit field would be useful for something where you have a lot of options which can be either enabled or disabled, such as configurations for a network protocol. Although this is often more useful in the actual network packet to store the configuration in the smallest possible space





Smart pointers are safer that normal pointers as they avoid bugs that could be caused by misuse of pointers, these are more useful in situations where computing resources and high performance aren't so important, as they reduce development time.





Bit masking is useful for checking if a particular bit or set of bits, is set or not, see bit fields above..





function pointers are useful when you have multiple functions to do a similar task but for different situations. eg if you make a general method to sort two lists objects you could pass a function pointer as well which is the function which defines what values are put above each other or below each other. so then youd have a function for ints which tests greater than or less than, then a fucntion for strings which checks for alphabetic order....etc

No comments:

Post a Comment