Testing auto feature on C++11

Hi friends,

Am trying to test this new 'auto' feature on C++11 version.

Here is my problem:
^
santos@santos-HCL-ME-Laptop:~/c++$ cat ./First_go.cpp
#include <iostream>

int main(int argC, char* argV[]){

auto i = 10.25 ;
std::cout<<"i after using auto"<<i<<std::endl ;

return 0 ;
}
santos@santos-HCL-ME-Laptop:~/c++$ g++ --version
g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Copyright (C) 2013 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.

santos@santos-HCL-ME-Laptop:~/c++$ g++ First_go.cpp
First_go.cpp: In function ‘int main(int, char**)’:
First_go.cpp:5:8: error: ‘i’ does not name a type
auto i = 10.25 ;
^
First_go.cpp:6:36: error: ‘i’ was not declared in this scope
std::cout<<"i after using auto"<<i<<std::endl ;

Seems like my g++ version supports this C++11 auto feature, am not sure whatz wrong, appreciate any help :)

Many Thanks,
Santee
Last edited on
-std=C++11
or somesuch.
http://stackoverflow.com/questions/10363646/compiling-c11-with-g

Like helios said, enable C++11 support.
If you use an IDE go look into options, or if you use just a shell be sure to pass -std=c++11 to g++, as in:

$ g++ -std=c++11 First_go.cpp

Holy Lord !!
Amazing, it worked :D

Thanks helios & Catfish :D

Just to add a Q: Does this auto decrease the C speed ?

Like literally which one is more quicker:
int some_func(){
//return some shite !
} ;

or

auto some_func(){
//return some shite
} ;
No it does not affect the speed of the program at run-time. It might take longer to figure out the return type of the function though. ;)
haha ic, thanks Peter :)
Topic archived. No new replies allowed.