jeudi 5 mars 2015

I confused about constexpr function?

In C++ primer fifth,§6.5.2



A constexpr function is defined like any other function but must meet certain restrictions: The return type and the type of each parameter in a must be a literal type (§2.4.4, p. 66), and the function body must contain exactly one return statement



but another sentence in this chapter (page 239)



A constexpr function is permitted to return a value that is not a constant




// scale(arg) is a constant expression if arg is a constant expression
constexpr size_t scale(size_t cnt) { return new_sz() * cnt; }


Is it a contradictory summary? I confused about it .

The return type of scale is liberal type ?


Aucun commentaire:

Enregistrer un commentaire