I have a class MyClass as follows:
class MyClass {
public:
MyClass(vector<vector<float>> arg) {
// some code here
}
MyClass(std::initializer_list<std::initializer_list<float>> arg)
: MyClass(vector<vector<float>>(arg)) {
}
// other class members
};
I'm trying to use a delegating constructor above, as I want an instance of MyClass to be constructed from both std::initializer_list<std::initializer_list<float>> and vector<vector<float>> types, and the constructor code blocks are identical. So I'm trying to delegate the construction of the nested initializer lists by initializing a multidimensional vector and using its constructor.
However, the above code gives me a compiler error:
no instance of constructor "std::__1::vector<_Tp, _Allocator>::vector [with _Tp=std::__1::vector<float, std::__1::allocator<float>>, _Allocator=std::__1::allocator<std::__1::vector<float, std::__1::allocator<float>>>]" matches the argument list -- argument types are: (std::initializer_list<std::initializer_list<float>>)
In file included from /opt/wandbox/gcc-9.3.0/include/c++/9.3.0/vector:67,
from prog.cc:11:
/opt/wandbox/gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:622:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = std::vector<float>; _Alloc = std::allocator<std::vector<float> >; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<std::vector<float> >]'
622 | vector(initializer_list<value_type> __l,
| ^~~~~~
/opt/wandbox/gcc-9.3.0/include/c++/9.3.0/bits/stl_vector.h:622:43: note: no known conversion for argument 1 from 'initializer_list<std::initializer_list<float>>' to 'initializer_list<std::vector<float>>'
622 | vector(initializer_list<value_type> __l,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
What am I doing wrong here?