我刚刚学习了c++中的declval关键字,我想知道为什么在下面的代码中
(std::add_rvalue_reference<Foo>::type).constFunc7() x = 3;
没有编译。 decltype(declValCustom<Foo>().constFunc7()) y = 3;
加上declValCustom
的模板声明不就等于吗?
#include <iostream>
#include <utility>
using namespace std;
struct Foo
{
int constFunc7() { return 7; }
};
template< class T >
typename std::add_rvalue_reference<T>::type declValCustom();
int main()
{
// (std::add_rvalue_reference<Foo>::type).constFunc7() x = 3; // not working
decltype(declValCustom<Foo>().constFunc7()) y = 3; // ok
decltype(std::declval<Foo>().constFunc7()) z = 3; // ok
}