Czy może ktoś mi wyjaśnić, czemu to się kompiluje:
#include <iostream>
#include <set>
using namespace std;
set<int, bool(*)(int, int)>
remaining([](int a, int b)->bool
{return a < b;});
int main() {}
A to nie:
#include <iostream>
#include <set>
using namespace std;
struct struktura
{
set<int, bool(*)(int, int)>
remaining([](int a, int b)->bool
{return a < b;});
};
int main() {}
I pluje dziwacznymi błędami kompilacji, jako są:
prog.cpp:8:15: error: expected identifier before '[' token
remaining([](int a, int b)->bool
^
prog.cpp:8:33: error: creating array of functions
remaining([](int a, int b)->bool
^
prog.cpp:9:7: error: expected ')' before '{' token
{return a < b;});
^
prog.cpp:9:22: error: expected unqualified-id before ')' token
{return a < b;});
^
prog.cpp: In member function 'std::set<int, bool (*)(int, int)> struktura::remaining()':
prog.cpp:9:15: error: 'a' was not declared in this scope
{return a < b;});
^
prog.cpp:9:19: error: 'b' was not declared in this scope
{return a < b;});
^
Co za idiotyzm, nie tworzę żadnej tablicy funkcji....!!!!
Ten sam set
mogę zadeklarować w przestrzeni globalnej i działa (przetestowałem), ale jako pola struktury już nie mogę zadeklarować??