samedi 2 janvier 2021

c++ container inside another container

#include <bits/stdc++.h>

template <typename T>
struct Row {
    Row() { puts("Row default"); }
    Row(const Row& other) { puts("Row copy"); }
    Row(Row&& other) { puts("Row move"); }
    Row(T x) { puts("Row int"); }
};

int main() {
  Row<Row<int>> x (10); // this works
  Row<Row<int>> x2 = 10; // error
}

Why the code doesn't work? I know that first one performs direct initialization and the second one is copy initialization but still when it comes to container inside a container I doesn't get easy for me.

compiler: clang c++20 no viable conversion from 'int' to 'Row<Row >'

Row<Row<int>> x2 = 10

Aucun commentaire:

Enregistrer un commentaire