gcc v. 4.7.1: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11

Hi

I am just reading C++ Primer, fifth edition and I am trying to run example in section 1.5.2. A First Look at Member Functions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream> 
#include "Sales_item.h" 
int main() {     
Sales_item item1, item2;     
std::cin >> item1 >> item2;     
// first check that item1 and item2 represent the same book    
 if (item1.isbn() == item2.isbn()) {         
std::cout << item1 + item2 << std::endl;         
return 0;   // indicate success     
} else {         
std::cerr << "Data must refer to same ISBN"                   
<< std::endl;         
return -1;  // indicate failure    
 }
}


In Cygwin on Windows PC I am using gcc v. 4.7.1.
But when I want to run this program terminal complains:

Sales_item.h:56:20: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11 [enabled by default]
Sales_item.h:70:27: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
Sales_item.h:71:22: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
1.5.2_Sales_item_sameISBN.cpp: In function ‘int main()’:
1.5.2_Sales_item_sameISBN.cpp:16:2: error: expected ‘;’ before ‘}’ token


In Terminal I also tried commands
-std=c++11
or std=c++11
or -std=gnu++11
or std=gnu++11
or -std=c++0x
or std=c++0x

but with no luck.

I am very sory, if I am bothering, but I don’t know whom can I ask.
I would have thought the warnings would go away when you pass -std=c++11 to the compiler.

The error looks like it's caused by a missing semicolon. What is line 16 in the real code?
when I pass -std=c++11, then I get:
-bash: -std=c++11: command not found

in real code I forgot ; at the and of 13th line
You should pass -std=c++11 to the compiler (g++).
Oh, lot of thanks.

When I put g++ -Wall -o 1.5.2 1.5.2_Sales_item_sameISBN.cpp -std=c++11
it worked.

Anyway I am wondering why compilation doesn't work without -std=c++11, if it is enabled by default.
I think the output us lying. -std=gnu++11 is not the default.

EDIT: Maybe they mean that non-static data member initializers are enabled by default and it gives you a warning because it doesn't exist in the version of C++ that is being used.
Last edited on
Thank You for explanation.
Topic archived. No new replies allowed.