我有點新的C++ 0x中,任何人都可以向我解釋爲什麼下面的編譯失敗:C++ lambda表達式幫助
void memory_leak_report()
{
std::cout.flags(std::ios::showbase);
std::for_each(allocation_records.begin(), allocation_records.end(),
[] (const struct memory_leak_report& rec) {
std::cout << "memory leak at: " << rec.file << ": line " << rec.line
<< std::hex << ", address: " << rec.address << std::dec
<< ", size:" << rec.size << std::endl;
});
}
其中allocation_records定義爲:std::list<struct memory_allocation_record> allocation_records
和memory_allocation_record
是一個簡單的C風格的數據結構。 G ++ -Wall -g -o頁頭的main.cpp -std =的C++ 0x
我得到的錯誤是:
struct memory_allocation_record {
const char *func;
const char *file;
unsigned int line;
unsigned int size;
unsigned long address;
};
我試着編譯它 在功能ג_功能該標準::的for_each(_IIter,_IIter,_Funct)[與_IIter =標準:: _ List_iterator,_Funct = memory_leak_report()::]
錯誤:不對應的調用(memory_leak_report()::)(memory_allocation_record &)
注:候選人是:void(*)(const memory_leak_report( ):: memory_leak_report &)
你有什麼錯誤? – jalf
什麼是錯誤?不要說'struct',那不是C++。只是'const memory_leak_report&rec'很好。 –
我總是發現模板編譯錯誤有點神祕,但錯誤是: – Arjor