Cast integral type passed by reference

If you have an integral type t1 and a function that gets the smallest possible integral type t2 by reference, would it be problematic to call the function ((t2) var_t1)?

+3
source share
4 answers

It would be nice to use t2if and only if the function took a link constant, in which case the time created by the cast before t2can be tied to it.

Since this defeats the purpose of referencing an integral type, I would suggest that the reference is not constant, so the answer is: yes, that would be problematic. To be clear, it will not even be compiled if you click on t2.

, function t1, reinterpret_cast /. undefined, .

+2

, const, , tempory .

const, , , .

+1

const, .

+1

C, " " , & . :

function((t2 [1]){ (t2)var });

Note that this is valid C, but not C ++, one of the reasons why you shouldn't mix C and C ++ tags ...

0
source

All Articles