Thread: casting
View Single Post
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: casting

 
0
  #2
Jan 11th, 2009
First, the compiler will provide a warning (not error. Warnings are not fatal) for not casting between int and size_t... but there is no harm in doing either for (int i=0; i <(int)somestring.length(); i++) or for (size_t i=0; i < somestring.length(); i++) {. There is nothing wrong with casting... but you need to understand the implications in so doing.... what happens if you cast a float to an int? What about an int to a float? Is upcasting an inheritance tree ok? Just out of curiosity, if you didn't have casts, how could you make use of a void pointer? My point here, is that casting has very valid and useful purposes, but you must absolutely know what happens to the data when you do it.
Reply With Quote