c++ - If QList instance is const, does it mean each element is constant? -


the following code fails compile:

void func(const qlist<int>& list){   auto& elem = list[0]; } 

the problem cannot bind const element non-const reference. following code works:

const auto& elem = list[0]; 

can explain why passing list const makes element const?

can explain why passing list const makes element const?

this semantics standard containers following. here's reason can see:

const int arr1 = {10, 20}; arr1[0] = 40; // error. elements of arr1 cannot modified.  const std::vector<int> arr2 = {10, 20}; arr2[0] = 40; // same semantics. error. elements of arr2 cannot modified. 

extending logic qlist, elements of qlist const if qlist const.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -