C++: Hidden array copy operation
A fixed-size array type in C++ does not have a copy constructor or a copy assignment. The following code won't compile: int a[2] = {1, 2}; int b[2] = a; A recommended way to fix this is to use std::array from the header <array> instead because it supports copying (and more): std::array<int, 2> a = {1, 2}; std::array<int, 2> b = a; Alternatively, one can resort to std::copy in <algorithm> , or the old school std::memcpy in <cstring> . Interestingly, the C++ language does have a way to copy fixed-size arrays, but it can only be accessed via a lambda capture. Here's an example that demonstrates that an array copy is actually done when it's captured by value into a lambda expression: (click this repl.it link if you want to play with the code) #include <functional> #include <iostream> using namespace std; struct LoudInt { int v; LoudInt(int v): v{v} { cout << "LoudIn...