constexpr Array(const std::initializer_list<T>& x)
: size(x.size()), data(x.begin()) {}The underlying array is not guaranteed to exist after the lifetime of the original initializer list object has ended. The storage for std::initializer_list is unspecified (i.e. it could be automatic, temporary, or static read-only memory, depending on the situation).
The underlying array is a temporary array of type const T[N], in which each element is copy-initialized (except that narrowing conversions are invalid) from the corresponding element of the original initializer list. The lifetime of the underlying array is the same as any other temporary object, except that initializing an initializer_list object from the array extends the lifetime of the array exactly like binding a reference to a temporary (with the same exceptions, such as for initializing a non-static class member). The underlying array may be allocated in read-only memory.
std::array, который позволил бы инициализацию произвольной длины для объекта этого типа.int arr = {1, 2, 3}; - это будет компилироваться, как думаешь?int arr[] = {1, 2, 3};, то точно ли 3 вернет операция sizeof(arr)? Я так не думаю. на вакансиях часто пишут чтобы имелся опыт разработки в играх от 1 - 3 лет , и не понимая что это значит
std::vector<man> addMan(std::vector<man>& v, int n) {
//man turnMan;
for(int i = 0; i < n; i++) {
v.push_back(turnMan);
v[i].data = i;
}
return v;
}n, какова его семантика? Почему ты передаешь семантику персоны (т.е. единичного числа, скорее всего индекса) в качестве аргумента для n?v[i].data = i;, а не v.back().data = i;? Может быть у тебя и тут тоже логика разрушена конфликтами семантики между v, i и n?bool isQuiet() {
if (this->isWorry) {
return false;
} else {
return true;
}
}lvalue reference буквально означает ссылку на значение.forward declaration)? Можно ли хранить ссылки на объекты незавершенного типа? 5 - это правильно. Почему будет выведено именно это число? Почему это не означает, что *p имеет ссылочный тип? Что означает "передача по значению"? Что означает "передача по ссылке"?struct Foo final
{
int a;
Foo() { std::cout << "Foo::Foo()" << std::endl; };
~Foo() { std::cout << "Foo::~Foo()" << std::endl; };
};
// ...
Foo* a = new Foo{};
Foo& b = *a;
Foo& c = *a;
Foo& d = *a;
Foo& e = *a;
Foo& f = *a;
delete a;"Foo::Foo()" и "Foo::~Foo()"? Почему именно столько раз?если х имеет тип указателя на другой тип Т, то разыменование х имеет тип Т, а не Т&&
refers to разве означает, что тип выражения - ссылка?
refersозначает "относиться" или "ссылаться".struct Foo final
{
int bar = 0;
};
// ...
Foo a;
Foo* p = &a;
(*p).bar = 5;
std::cout << a.bar;