// includes ...intmain(){autosquare=[](autox){returnx*x;};autotwice=[](autox,autof){returnf(x)+f(x);};std::cout<<twice(5,square)<<std::endl;std::cout<<twice(5.1,square)<<std::endl;return0;}
Le but étant de vérifier comment il instancie les différentes versions en fonction des types.
Compilation :
$ g++ -std=c++11 main.cpp
main.cpp: In function'int main()':
main.cpp:29:25: error: parameter declared 'auto'
auto square=[](auto x){return x * x;};
^
main.cpp: In lambda function:
main.cpp:29:37: error: 'x' was not declared in this scope
auto square=[](auto x){return x * x;};
^
main.cpp: In function'int main()':
main.cpp:30:24: error: parameter declared 'auto'
auto twice=[](auto x, auto f){return f(x) + f(x);};
^
main.cpp:30:32: error: parameter declared 'auto'
auto twice=[](auto x, auto f){return f(x) + f(x);};
^
...
Je ne suis pas un pro du C++11, quelqu’un pourrait m’expliquer ?
[^] # Re: simple ?
Posté par Anthony Jaguenaud . En réponse au journal Rust en version 0.12. Évalué à 2.
Bon, j’ai essayé ce code :
Le but étant de vérifier comment il instancie les différentes versions en fonction des types.
Compilation :
Je ne suis pas un pro du C++11, quelqu’un pourrait m’expliquer ?