fork(2) download
  1. #include <iostream>
  2. #include <utility>
  3.  
  4. class test
  5. {
  6. private:
  7. test(int) { }
  8. public:
  9. test foo() { return *this; }
  10.  
  11. static const char *name() { return "test"; }
  12. };
  13.  
  14. int main()
  15. {
  16. std::cout << decltype(test().foo())::name() << std::endl; // 1
  17. std::cout << decltype(std::declval<test>().foo())::name() << std::endl; // 2
  18. }
  19.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:16:29: error: no matching function for call to ‘test::test()’
  std::cout << decltype(test().foo())::name() << std::endl;               // 1
                             ^
prog.cpp:16:29: note: candidates are:
prog.cpp:7:2: note: test::test(int)
  test(int) { }
  ^
prog.cpp:7:2: note:   candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(const test&)
 class test
       ^
prog.cpp:4:7: note:   candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(test&&)
prog.cpp:4:7: note:   candidate expects 1 argument, 0 provided
prog.cpp:16:29: error: no matching function for call to ‘test::test()’
  std::cout << decltype(test().foo())::name() << std::endl;               // 1
                             ^
prog.cpp:16:29: note: candidates are:
prog.cpp:7:2: note: test::test(int)
  test(int) { }
  ^
prog.cpp:7:2: note:   candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(const test&)
 class test
       ^
prog.cpp:4:7: note:   candidate expects 1 argument, 0 provided
prog.cpp:4:7: note: constexpr test::test(test&&)
prog.cpp:4:7: note:   candidate expects 1 argument, 0 provided
prog.cpp:16:15: error: decltype evaluates to ‘<type error>’, which is not a class or enumeration type
  std::cout << decltype(test().foo())::name() << std::endl;               // 1
               ^
stdout
Standard output is empty