S
Spoon
Hello,
Could someone explain why the following code is illegal?
(I'm trying to use a list of (C-style) arrays.)
#include <list>
typedef std::list < int[2] > foo_t;
int main()
{
int v[2] = { 12, 34 };
foo_t bar;
bar.push_front(v);
return 0;
}
$ g++ -std=c++98 -Wall foo.cxx
stl_construct.h: In function `void std::_Construct(_T1*, const _T2&)
[with _T1 = int[2], _T2 = int[2]]':
stl_list.h:438: instantiated from `std::_List_node<_Tp>*
std::list<_Tp, _Alloc>::_M_create_node(const _Tp&) [with _Tp = int[2],
_Alloc = std::allocator<int[2]>]'
stl_list.h:1163: instantiated from `void std::list<_Tp,
_Alloc>::_M_insert(std::_List_iterator<_Tp>, const _Tp&) [with _Tp =
int[2], _Alloc = std::allocator<int[2]>]'
stl_list.h:755: instantiated from `void std::list<_Tp,
_Alloc>:
ush_front(const _Tp&) [with _Tp = int[2], _Alloc =
std::allocator<int[2]>]'
foo.cxx:7: instantiated from here
stl_construct.h:81: error: ISO C++ forbids initialization in array new
Do I have to wrap the array in a struct?
#include <list>
struct sfoo { int v[2]; };
typedef std::list < sfoo > foo_t;
int main()
{
sfoo s = { 12, 34 };
foo_t bar;
bar.push_front(s);
return 0;
}
Regards.
Could someone explain why the following code is illegal?
(I'm trying to use a list of (C-style) arrays.)
#include <list>
typedef std::list < int[2] > foo_t;
int main()
{
int v[2] = { 12, 34 };
foo_t bar;
bar.push_front(v);
return 0;
}
$ g++ -std=c++98 -Wall foo.cxx
stl_construct.h: In function `void std::_Construct(_T1*, const _T2&)
[with _T1 = int[2], _T2 = int[2]]':
stl_list.h:438: instantiated from `std::_List_node<_Tp>*
std::list<_Tp, _Alloc>::_M_create_node(const _Tp&) [with _Tp = int[2],
_Alloc = std::allocator<int[2]>]'
stl_list.h:1163: instantiated from `void std::list<_Tp,
_Alloc>::_M_insert(std::_List_iterator<_Tp>, const _Tp&) [with _Tp =
int[2], _Alloc = std::allocator<int[2]>]'
stl_list.h:755: instantiated from `void std::list<_Tp,
_Alloc>:
std::allocator<int[2]>]'
foo.cxx:7: instantiated from here
stl_construct.h:81: error: ISO C++ forbids initialization in array new
Do I have to wrap the array in a struct?
#include <list>
struct sfoo { int v[2]; };
typedef std::list < sfoo > foo_t;
int main()
{
sfoo s = { 12, 34 };
foo_t bar;
bar.push_front(s);
return 0;
}
Regards.