Regular cast vs. static_cast vs. dynamic_cast [duplicate]

This question already has answers here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? (9 answers) Closed 7 years ago. I’ve been writing C and C++ code for almost twenty years, but there’s one aspect of these languages that I’ve never really understood. I’ve obviously used regular casts i.e. MyClass *m = (MyClass *)ptr; … Read more

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? (Clarification: header files are not the only portable solution. But they are the most convenient portable solution.) 1 17 Caveat: It … Read more

C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?

C++11 introduced a standardized memory model, but what exactly does that mean? And how is it going to affect C++ programming? This article (by Gavin Clarke who quotes Herb Sutter) says that, The memory model means that C++ code now has a standardized library to call regardless of who made the compiler and on what … Read more

What are the basic rules and idioms for operator overloading?

Note: The answers were given in a specific order, but since many users sort answers according to votes, rather than the time they were given, here’s an index of the answers in the order in which they make the most sense: The General Syntax of operator overloading in C++ The Three Basic Rules of Operator … Read more