What is the meaning of ‘const’ at the end of a member function declaration?

When you add the const keyword to a method the this pointer will essentially become a pointer to const object, and you cannot therefore change any member data. (Unless you use mutable, more on that later). The const keyword is part of the functions signature which means that you can implement two similar methods, one …

Read more

What is std::move(), and when should it be used and does it actually move anything?

1. “What is it?” While std::move() is technically a function – I would say it isn’t really a function. It’s sort of a converter between ways the compiler considers an expression’s value. 2. “What does it do?” The first thing to note is that std::move() doesn’t actually move anything. It changes an expression from being …

Read more

Should I include or in C++ programs?

Consider the following programs: Sample 1: #include<stdio.h> int main() { printf(“Hello World”); return 0; } Sample 2: #include<cstdio> int main() { printf(“Hello World”); return 0; } Both work as expected. So which usage is more appropriate? The answer is: Neither! Surprised? Read on. The C++ Standard library provides all standard C headers for compatibility reason, …

Read more

What happens when an exception goes unhandled in a multithreaded C++11 program?

Nothing has really changed. The wording in n3290 is: If no matching handler is found, the function std::terminate() is called The behavior of terminate can be customized with set_terminate, but: Required behavior: A terminate_handler shall terminate execution of the program without returning to the caller. So the program exits in such a case, other threads …

Read more

What are all the member-functions created by compiler for a class? Does that happen all the time?

C++98/03 If they are needed, the compiler will generate a default constructor for you unless you declare any constructor of your own. the compiler will generate a copy constructor for you unless you declare your own. the compiler will generate a copy assignment operator for you unless you declare your own. the compiler will generate …

Read more