Daily C++11: Constexpr – generalized const expressions and updated PODs definition

A new feature of C++11 is to mark certain functions as constant expressions. For example, if one writes some functions like:

[code language=”cpp”]constexpr double getPI() {return 3.1415;}
constexpr double getE() {return 2.7182;}

const double PIPlusE = getPI() + getE();[/code]

Personally, I don’t find any use for this feature. Maybe someone could enlighten me?

Anyway, the second feature is that the definition of POD was updated. POD = plain old data, which means that the data can be manipulated by simply copying the data, with a basic memcpy. The definition was updated to, basically, stating that POD is any class or structure that:

  • has no virtual functions (including destructors)
  • has a POD as a base class (if derived)
  • has all the nonstatic data in one class and with the same access level (public, protected or private).

Sprijină dorinlazar.ro

GDPR

Uniunea Europeană vrea să vă informez că nu vă folosesc datele personale pentru nimic. Și o fac aici.