Что является результатом данной строки
И как производить обращение к элементам, в таком случае?
list<vector<string>> lvs {{"Hello", "World"}, {"Goodbye", "Universe"}, {"What", "am", "I", "doing"}};
for(auto it = list.cbegin(), it != list.cend(), ++it) {//Проходимся по всем элементам списка
cout << (*it)[1] << '\n';
// (*it) даст элемент списка: vector<string>
// Пы можем обратиться к элементу вектора при помощи оператора []
}
struct base
{};
struct derived: base
{};
//...
derived* d = new derived;
//Работает, безопасно
base* b = static_cast<base*>(d);
//Работает, безопасно так как b на самом деле указывает на derived
d = static_cast<derived*>(b);
b = new base;
//Undefined Behavior. Программа превращается в тыкву.
d = static_cast<derived*>(b);
А system("pause") платформонезависимый?Нет
Ведь программа сразу же закрывается. Или како-то это по другому решается?Настройте IDE нормально, либо запускайте программы из командной строки, а не двойным щелчком. Это нормальное и правильное поведение для консольных программ.
Ссылка используется только в случае с std::bad_alloc или с классами тоже?Стандарт обработки исключений в С++: бросать по значению, ловить по ссылке.
То есть, такого типа указатели нужно всегда инициализировать? Если не char* ptr = new char[SIZE], то char* ptr = NULL и на другой строке ptr = new char[SIZE]?Если
char* ptr = new char[SIZE]
бросит исключение, то переменной ptr не существует и удалять нечего. Нужно всегда инициализировать переменную при объявлении. Чем — другой вопрос.struct Outer
{
struct Inner;
};
struct Outer::Inner
{
Outer _outer;
Inner() : _outer() { }
};
Fl_Window(x,y,w,h,t.c_str());
Здесь вы создаёте временный локальный объект типа Fl_Window. Это точто то, что вам надо?mainWindow(int w, int h, int x, int y,const string& t) : Fl_Window(x,y,w,h,t.c_str())
{}
If T is a class type, and the type of other is different, or if T is non-class type, but the type of other is a class type, user-defined conversion sequences that can convert from the type of other to T (or to a type derived from T if T is a class type and a conversion function is available) are examined and the best one is selected through overload resolution. The result of the conversion, which is a prvalue temporary if a converting constructor was used, is then used to direct-initialize the object. The last step is usually optimized out and the result of the conversion is constructed directly in the memory allocated for the target object, but the appropriate constructor (move or copy) is required to be accessible even though it's not used.Грубо говоря сначала то, что справа неявно приводится к типу слева (при помощи конструктора) а потом используется для инициализации переменно с помощью move или copy-конструктора.
Ошибка. Почему?Потому что вы не вызываете оператор присваивания, а совершаете copy-initializtion. Вам может помочь простое правило: все действия совершаемые при объявлении переменной вызывают конструктор.
#include <algorithm>
#include <iostream>
#include <string>
int main()
{
std::string strings[] = {"143", "224", "168", "162", "165", "226"};
char line[16] {};
std::transform(std::begin(strings), std::end(strings), std::begin(line),
[](const std::string& s) {
return std::stoi(s); });
std::cout << line;
}