简体   繁体   中英

Can I use decltype without any instance variables?

There is a function I'm using from a library that has a macro-ridden output type:

STRANGE_MACRO(something) the_function(Type1 t, Type2 u);

I would like to define a variable that will take this return value without first declaring a Type1 or a Type2 .

I was hoping something like this would work:

decltype(the_function(Type1, Type2)) return_value;

But it doesn't work. Can I do this without figuring out what the macro evaluates to and without declaring a couple variables first?

这正是std::declval的用途:

decltype(the_function(std::declval<Type1>(), std::declval<Type2>())) return_value;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM