consideri codice semplice frammento diErrore di sintassi nel costruttore presa argomento di default `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;
}
Quando compilo in questo modo: clang++ -o foo foo.cpp
mi faccia errori:
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>())
^
stesso comportamento per clang 3.2 e clang 3.3.
Quindi mi chiedo se mi manca qualcosa o è un bug? GCC non si lamenta.
Puoi provare '{}' invece di '()' ? – stefan
Sì, sembra che ci sia un bug nelle tue versioni di clang. Testato con clang versione 3.5.0 (trunk 203891) e funziona perfettamente. –
Compila in glang ++ 3.5 (pre-3.5 dalla scorsa settimana o giù di lì) e gcc 4.8.2, oltre a clang 2.9 e g ++ 4.6.3. Quali sono tutti i compilatori che ho sulla mia macchina corrente ... –