請解釋如何自動類型推演作品與舉動語義當用於什麼`汽車&& i = FOO();'意味着
#include <iostream>
template <typename T>
struct A {
static void type() { std::cout << __PRETTY_FUNCTION__ << std::endl; }
};
float& bar() {
static float t = 5.5;
return t;
}
int foo() {
return 5;
}
int main() {
auto &&a1 = foo(); // I expected auto -> int (wrong)
auto &&a2 = bar(); // I expected auto -> float& (correct)
A<decltype(a1)>::type();
A<decltype(a2)>::type();
}
輸出是:
static void A<T>::type() [with T = int&&]
static void A<T>::type() [with T = float&]
你的輸出顯示'int'和'float'? – Brian