Funzioni automatiche in c ++

3

Non sono così familiare con C ++. Qualcuno può per favore informarmi su cosa fa questa linea (in dettaglio):

auto add_element = [&rows,&cols,&values](size_t row, size_t col, double value)
{
    rows.push_back(int(row));
    cols.push_back(int(col));
    values.push_back(value);
};

Righe, colonne, valori sono vettori evidenti.

È lo stesso di void add_element (vector & rows, size_t row, .....)

    
posta Johan 11.06.2013 - 11:01
fonte

1 risposta

5

Questo definisce e memorizza un lambda. Leggi qui su maggiori dettagli o su google up su C ++ 11 e lambda.

One of the most exciting features of C++11 is ability to create lambda functions (sometimes referred to as closures). What does this mean? A lambda function is a function that you can write inline in your source code (usually to pass in to another function, similar to the idea of a functor or function pointer). With lambda, creating quick functions has become much easier, and this means that not only can you start using lambda when you'd previously have needed to write a separate named function, but you can start writing more code that relies on the ability to create quick-and-easy functions. In this article, I'll first explain why lambda is great--with some examples--and then I'll walk through all of the details of what you can do with lambda...

    
risposta data 11.06.2013 - 11:08
fonte

Leggi altre domande sui tag