C++: declared as function returning a function?

#include <iostream>

template<class T>
class val_of {
public:
  const T &operator()(const T &t = T()) const { return t; }
};

int main()
{
  int a = val_of<int>()(6);
  std::cout << a << std::endl;
  int A = val_of<int>{}(-6);
  std::cout << A << std::endl;
  int b(val_of<int>()(7));
  std::cout << b << std::endl;
  int B(val_of<int>{}(-7));
  std::cout << B << std::endl;

  int c = val_of<int>()();
  std::cout << c << std::endl;
  int C = val_of<int>{}();
  std::cout << C << std::endl;
  int d(val_of<int>()());
  // int d((val_of<int>())());
  std::cout << d << std::endl;
  int D(val_of<int>{}());
  std::cout << D << std::endl;

  return 0;
}

Compile with g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0:

test.cpp: In function ‘int main()’:
test.cpp:24:9: error: ‘parameter’ declared as function returning a function
   24 |   int d(val_of<int>()());
      |         ^~~~~~~~~~~
test.cpp:26:16: warning: the address of ‘int d(...)’ will never be NULL [-Waddress]
   26 |   std::cout << d << std::endl;
      |                ^

 

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^