The topic title says it all. I dont really know the difference, can anyone tell me?
Thanks!
The topic title says it all. I dont really know the difference, can anyone tell me?
Thanks!
in C++ the difference is somewhat blurred because supposedly you can inherit from a union . Forget that though.
union really represents one piece of memory that can be referenced many different ways.
a struct represents a group of many pieces of data sequentially in memory.
get it? a union isn't a group as much as it is a reuse of one piece of memory.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
Union really isn't needed much anymore since todays computers can spare the memory you will waste when having an int and an double even if you only need the double in one situation.
Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something
Oh
Thanks!
The only place I have found these usefull has been with certain Btrieve (yuck!) related database functions. One function call (Get Next Extended) has you initializing a buffer with information such as what criteria you want to have match for retrieval of records and what particular fields you want to extract from the database where that criteria matches. You then pass a pointer to the buffer to the function and it searches through the database and returns the data in the same buffer you gave to the function. When this happens, what is in the buffer after the call is different from what you put into the function prior to the call. Using a union here makes setting up the buffer and then extracting the data from the buffer once the call is complete easy. The union in this case contains two struct elements; one holds the information necessary for defining the criteria and fields you want from the database, the other struct holds those fields from the records you requested. Aside from that, I have never found them particularly usefull.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens