They’re not functions. They’re just alternate syntax for type-casting. char(x)
is more-or-less equivalent to static_cast<char>(x)
.
In general, in C++, one should prefer the C++-specific constructs for casting objects (static_cast
, dynamic_cast
, const_cast
, and reinterpret_cast
), as those help ensure you don’t do anything dumb when casting objects. So in your code example, I’d recommend rewriting it as
result += static_cast<char>(static_cast<int>(text[i]+s-65)%26 +65);
But functionally, it’s all identical.
4
solved char () and int () are functions in c++? [duplicate]