Inspired by Zekes passionate blogging here, I decided to write a blog. On a topic that I think deserves a bit of thought... *drumroll* Casting in C++. Oh yeah. It's pretty, eh? Code: const int i = 10; char* c = reinterpret_cast<char*>(const_cast<int*>(&i)); If coming from a C background you are likely to have a face expression similar to this: - longing for your good old Code: char* c = (char*)&i; And I can honestly understand why people despise ...
const int i = 10; char* c = reinterpret_cast<char*>(const_cast<int*>(&i));
char* c = (char*)&i;
The final section of Beyond the C++ Standard Library: An Introduction to Boost is about enhancing function support. I would love to tell you wonderful stories about how Bind, Lambda, Function, and Signals can revolutionize your programming, but the reality is that what I really learned was the limitations of my knowledge of C++. The C++ Standard Template Library, part of the Standard Library, is loaded with tons of useful little algorithms, containers, and amazing functionality that ...
The Boost library adds four "casts" to the C++ language: polymorphic_cast, polymorphic_downcast, numeric_cast, and lexical_cast. The first two, polymorphic_cast and polymorphic_downcast allow you to be a little bit safer or clearer than using dynamic_cast and static_cast. These are interesting to me, but nothing compared to the awesomeness that is numeric_cast and lexical_cast. numeric_cast allows you to deal with overflows when converting between integral types. It handles both ...
Yesterday I was re-reading about the sentinel-control-structure, and I came back to my problem on why the author initialize the counter from 0 or from 1 (in two different cases). For the discussion thread, please look at here http://forum.codecall.net/c-c/14435-...structure.html I will first let you guys see what are the two cases: First case (definite-counter-control structure) Task: You are ask to develop a program that will ...