|
|
By Alex, on November 30th, 2011
override
When working with derived classes, it’s fairly easy to inadvertently create a new virtual function in the derived class when you actually meant to override a function in the base class. This happens when you fail to properly match the function prototype in the derived class with the one in the base class. . . . → Read More: B.6 — New virtual function controls: override, final, default, and delete
By Alex, on November 27th, 2011
Delegating constructors
In C++03, there are often cases where it would be useful for one constructor to call another constructor in the same class. Unfortunately, this is disallowed by C++03. Commonly this ends up resulting in either duplicated code:
class Foo { public: Foo() { // code to do A } Foo(int nValue) { . . . → Read More: B.5 — Delegating constructors
By Alex, on November 27th, 2011
Initializer lists
C++03 has partial support for initializer lists, allowing you to use initializer lists for simple aggregate data types (structs and C-style arrays):
struct Employee { int nID; int nAge; float fWage; }; Employee sJoe = {1, 42, 60000.0f}; int anArray[5] = { 3, 2, 7, 5, 8 };
However, this doesn’t work . . . → Read More: B.4 — Initializer lists and uniform initialization
By Alex, on November 27th, 2011
Range-based for statements
In C++03, stepping through all the values of a sequence requires a lot of code, particularly when using the iterator syntax:
for (std::vector<int>::iterator itr = myvector.begin(); itr != myvector.end(); ++itr)
In C++11, the auto keyword makes this a little better:
for (auto itr = myvector.begin(); itr != myvector.end(); ++itr)
But this . . . → Read More: B.3 — Range-based for statements and static_assert
By Alex, on November 25th, 2011
Type long long
In you recall from lesson 2.4 — Integers, the largest integer type C++03 defines is “long”. Long has a platform-specific size that can be either 32 or 64 bits. C++ defines a new type named long long that’s guaranteed to be at least 64 bits in length. Because “long long” was . . . → Read More: B.2 — Long long, auto, decltype, nullptr, and enum classes
|
|