jeudi 1 septembre 2022

Question about decltype and `std::vector::operator[]`

Since there are two overloading functions for std::vector::operator[], one returns a reference, and the other one returns a const reference.

Why the type of reg_auid is char& other than const char&, which is indcated by vscode?

#include <vector>

int main()
{
    std::vector<char> data_array{100};

    const int IDX = 1;

    //why the type of reg_auid is char& other than const char&
    decltype(data_array[IDX]) reg_auid = data_array[IDX]; 
}

Aucun commentaire:

Enregistrer un commentaire