Rozważmy prosty kod urywekbłąd składni w domyślnym argumentem podejmowanie konstruktor `std :: map`
#include <map>
#include <string>
struct Foo
{
Foo(const std::map<std::string, int> & bar = std::map<std::string, int>())
:bar(bar)
{ }
std::map<std::string, int> bar;
};
int main(int argc, char ** argv)
{
return 0;
}
Kiedy skompilować to tak: clang++ -o foo foo.cpp
I twarz błędy:
foo.cpp:7:73: error: expected ')'
Foo(const std::map<std::string, int> bar = std::map<std::string, int>())
^
foo.cpp:7:8: note: to match this '('
Foo(const std::map<std::string, int> bar = std::map<std::string, int>())
^
foo.cpp:7:68: error: expected '>'
Foo(const std::map<std::string, int> bar = std::map<std::string, int>())
^
samo zachowanie dla clang 3.2 i clang 3.3.
Zastanawiam się więc, czy czegoś brakuje, czy jest to błąd? GCC nie narzeka.
można spróbować '{}' zamiast '()' ? – stefan
Tak, wydaje się, że jest to błąd w twoich wersjach klang. Testowane z wersją klangową 3.5.0 (bagażnik 203891) i działa dobrze. –
Kompiluje się w glang ++ 3.5 (sprzed 3.5 z ostatniego tygodnia) i gcc 4.8.2, a także clang 2.9 i g ++ 4.6.3. Jakie są wszystkie kompilatory, które mam na mojej obecnej maszynie ... –