-2

I am trying to compile some c++ I got from a book I am going through, when I try to compile I get this warning followed by 5 related errors.

main.cpp:16:9: warning: variable templates are a C++14 extension 
[-    Wc++14-extensions]
int table<RecordType>::CAPACITY;
    ^

I have never given a thought to updating c++ or being certain of what version I am using. I am compiling this in a mac using g++.

natedaswas
  • 83
  • 5

4 Answers4

2

You may enable it with -std=c++14 flag. However, your GCC version should support it in the first place. Till GCC 4.9.3, you could use -std=c++1y whereas since GCC 5.2, it supports c++14 flag as well. For more info, refer to this.

Community
  • 1
  • 1
rurtle
  • 411
  • 4
  • 18
1

Pass the -std=c++14 flag. There are also older versions with partial C++14 support which don't support -std=c++14 yet; for these, pass the -std=c++1y flag.

Brian Bi
  • 111,498
  • 10
  • 176
  • 312
1

You need to tell the compiler which version of the standard to compile to.
Try g++ -std=c++14.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
1

While -std=c++14 that others are recommending will enable C++14 feature support, it will also disable a bunch of things that are enabled by default, including support for advanced POSIX APIs.

Unless you specifically want to disable G++ extensions, you should use -std=gnu++14 not -std=c++14

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • Where I'd rather advise beginners to switch off extensions via `-std=c++14` (and write portable code) until they reach a point where they need to use them. – Pixelchemist Jun 15 '16 at 01:15
  • @Pixelchemist: If it were just language extensions, I'd agree with you. But portable (part of the Single Unix Specification) library functions get turned off because the header files have guards that test for `_GNU_SOURCE` (which should get turned off) and `_XOPEN_SOURCE` (which should not -- but it is). – Ben Voigt Jun 15 '16 at 01:54
  • My comment holds: Rather use standard c++ than extensions where possible and only resort to extensions if required (or if for any other good reason the extensions is to be used).I don't consider POSIX to be actually downright *portable*. – Pixelchemist Jun 15 '16 at 11:09