mardi 5 mars 2019

Can I safely cast to a function returning void?

Casting between function types which take different arguments or return different types is not safe for obvious reasons.

What isn't obvious (to me) is whether it should be safe to cast to a function pointer type where the return type is void (and the argument types are the same).

Is there a mechanism to safely cast for instance int (*)() to void (*)()? static_cast fails here. reinterpret_cast works, but is unsafe.

Is there a safe way?

std::function<> seems to pull off the trick, but I can't seem to peer through it's labyrinth implementation to see how.

Aucun commentaire:

Enregistrer un commentaire