I’m preparing some slides to explain how to write better code with C++11/14, and I wanted to start from the last thing I wrote about here, the use of keywords final and override. The scope of my previous post, albeit a bit cryptic, was to show how those keywords are context-sensitive, so you can also use final and override as type names, as …
Continue reading Final & Override againC++
namespace override { class override { }; class override_final { ::override::override override; public: virtual ::override::override & final() { return override; } }; } namespace final { class final final : public override::override { }; class final_override final : public override::override_final { ::final::final override; public: ::final::final & final() override final { return override; } }; } …
Continue reading Please, use final and override!Naming a method after the class Consider this class: struct B { B() {} int B() { return 42; } // FAIL! }; This code is illegal because a method name can’t be named after the class name. I was wondering if there’s a particular reason for this, since it’s a restriction you can easily overcome by writing: struct …
Continue reading Naming restrictions for methods in C++In these days I’m porting a library from Qt4 to Qt5, and here’s how sticking to C++11 syntax has helped me catching a subtle porting problem. I had a class subclassing QTcpServer, overriding a virtual method with this syntax: void incomingConnection(int descriptor) override; Specifying the method as override was enough to discover a breaking change in …
Continue reading Override and errorsLast month I bought a bunch of Raspberry PI 2 and started playing with them. I was a bit disappointed about the lack of modern tools in the standard Raspbian Wheezy distro, but I found out that Debian 8.0 (Jessie) is more advanced on that, but the process of downloading the image, modifying the files, …
Continue reading Using Raspberry PI 2 as a C++11/14 playgroundI never managed to remember the match between Visual Studio version, Visual C++ compiler version and Microsoft C/C++ compiler version. I took a minute to collect all the data quite some time to collect all this information, and leave it here for future reference: Product IDE version Solution version(s) Platform toolset _MSC_VER Visual Studio 2019 …
Continue reading Microsoft Visual C++ version MapTwo days ago I was asked to have a look at a nonworking piece of code, based on boost::program_options, which went like this: options_description desc(“Usage”); desc.add_options() (“host,h”, value<string>(), “The host.”) (“file,f”, value<string>(), “This is the file.”); (“mode,m”, value<string>(), “The mode.”); If you don’t recognise the syntax, know that add_options() method of options_description returns a builder object (options_description_easy_init), with an operator () taking three parameters, which …
Continue reading Funny bug #20150127Can C++ be explained with simple words, like talking to my dog? No. Luckily, I don’t have a dog either.
Continue reading C++ explained to my dog