C++11 : Lambda functions return value
Hey there. I installed the newest GCC version yesterday to try out the new C++ standard. I have added the command line argument so that it knows to use C++11 and compiled a sample code from CProgramming's webmaster successfully. I wanted to play around a little bit to learn how to use the new tools but it seems I can't make anything compile:
Code:
#include <iostream>
using namespace std;
void blah(int a) {
std::cout << a;
}
int main()
{
auto a = [] { return 1; };
blah(a);
blah([] { return 1; });
blah([] -> int { return 1; });
}
Code:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: entrant dans le répertoire « /cygdrive/c/Users/win7/Documents/NetBeansProjects/CppApplication_1 »
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/cppapplication_1.exe
make[2]: entrant dans le répertoire « /cygdrive/c/Users/win7/Documents/NetBeansProjects/CppApplication_1 »
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f build/Debug/Cygwin_4.x-Windows/main.o.d
g++-4.exe -std=c++0x -Wall -Wextra -c -g -MMD -MP -MF build/Debug/Cygwin_4.x-Windows/main.o.d -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
main.cpp: In function ‘int main()’:
main.cpp:13:11: erreur: invalid conversion from ‘int (*)()’ to ‘int’
main.cpp:13:11: erreur: initializing argument 1 of ‘void blah(int)’
main.cpp:14:26: erreur: invalid conversion from ‘int (*)()’ to ‘int’
main.cpp:14:26: erreur: initializing argument 1 of ‘void blah(int)’
main.cpp:15:36: erreur: invalid conversion from ‘int (*)()’ to ‘int’
main.cpp:15:36: erreur: initializing argument 1 of ‘void blah(int)’
make[2]: quittant le répertoire « /cygdrive/c/Users/win7/Documents/NetBeansProjects/CppApplication_1 »
make[1]: quittant le répertoire « /cygdrive/c/Users/win7/Documents/NetBeansProjects/CppApplication_1 »
make[2]: *** [build/Debug/Cygwin_4.x-Windows/main.o] Erreur 1
make[1]: *** [.build-conf] Erreur 2
make: *** [.build-impl] Erreur 2
BUILD FAILED (exit value 2, total time: 2s)
Obviously this is all the same syntax error, but I do not understand what my error is. From what I have seen online it seems that this is the way to do this :\