(sort i lambda) a to wszystko w metodzie.
Ostatnio zmodyfikowano 2014-12-07 14:28
toperko Temat założony przez niniejszego użytkownika |
(sort i lambda) a to wszystko w metodzie. » 2014-12-07 14:06:24 Witam, próbuję użyć sortowania w raz z lambdą w metodzie dla pewnej klasy. #include <iostream> #include <algorithm> using namespace std;
class klasa { public: int sortuj() { int a[ 10 ] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; sort( a, & a[ 10 ],[]( int x, int y ) { return x < y; } ); for( int i = 0; i < 10; i++ ) { printf( "%i ", a[ i ] ); } printf( "\n" ); } };
int main( int argc, char ** argv ) { klasa nowy; nowy.sortuj(); return 0; }
C:\main.cpp In member function 'int klasa::sortuj()': 10 54 C:\main.cpp [Warning] lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default] 10 56 C:\main.cpp [Error] no matching function for call to 'sort(int [10], int*, klasa::sortuj()::<lambda(int, int)>)' 10 56 C:\main.cpp [Note] candidates are: 63 0 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\algorithm In file included from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/algorithm 2 C:\main.cpp from main.cpp 5463 5 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\stl_algo.h [Note] template<class _RAIter> void std::sort(_RAIter, _RAIter) 5463 5 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\stl_algo.h [Note] template argument deduction/substitution failed: 10 56 C:\main.cpp [Note] candidate expects 2 arguments, 3 provided 63 0 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\algorithm In file included from c:\program files (x86)\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.1/include/c++/algorithm 2 C:\main.cpp from main.cpp 5499 5 c:\program files (x86)\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.7.1\include\c++\bits\stl_algo.h [Note] template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare) 10 56 C:\main.cpp [Error] template argument for 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)' uses local type 'klasa::sortuj()::<lambda(int, int)>' 10 56 C:\main.cpp [Error] trying to instantiate 'template<class _RAIter, class _Compare> void std::sort(_RAIter, _RAIter, _Compare)'
|
|
Monika90 |
» 2014-12-07 14:28:54
warning: lambda expressions only available with -std=c++11 or -std=gnu++11 |
Tu masz odpowiedź. |
|
« 1 » |