c++ - Difference between functional cast notation T(x) and static_cast<T>(x) -


(i know similar other questions on here, haven't found specifically, language-lawyerly, answer this precise detail. of near-duplicates asking whether should use static_cast on functional-style casts (answer: yes), or difference between static_cast , c-style casts.)

in c++, following 2 casts appear similar:

template<class t, class u> auto convert1(u&& u) {     return t( std::forward<u>(u) ); }  template<class t, class u> auto convert2(u&& u) {     return static_cast<t>( std::forward<u>(u) ); } 

is there any difference types t, u; or 100% identical in effect?

if different, i'd appreciate examples of places in standard library subtle difference relevant. (i mean how std::make_shared<t>(args...) specified construct object t(args...) instead of t{args...} because of subtle difference between t() , t{} there.)

the functional-style cast notation t(x) single argument defined standard identical c-style cast notation (t)x. c-style cast notation can conversion static_cast can do, , others (which may undesired), such casting away constness. example convert1 used convert int const* int* while convert2 not.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -