0

Description

I'm new to c++. My project needs to use any library, which is a new feature after c++ 17. After updating my compiler following this link. I still encounter an error. Here is the error message and my test code.

g++ version:

g++ (Ubuntu 6.5.0-2ubuntu1~16.04) 6.5.0 20181026
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Code

// test_c++17.cc
#include <any>
#include <iostream>

int main() {
  std::cout << "hello c++ 17" << std::endl;
}

Compile

gcc -std=c++17 test_c++17.cc -o test

Error Message

enter image description here

Community
  • 1
  • 1
Harold
  • 33
  • 5

1 Answers1

3

Per cppreference's C++ compiler support page, std::any is not supported until GCC 7. You will need to upgrade again to a more current version. Right now 9.2 is the most currently stable release.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • 1
    Also libstdc++'s [status page](https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2017) says the same. – walnut Mar 03 '20 at 18:46
  • Problem solved. After updating g++ to a newer version, the code can be compiled. Thanks. – Harold Mar 03 '20 at 20:01