Topic: STL map and pair classes
Author: jason@cygnus.com (Jason Merrill)
Date: 1995/08/25 Raw View
Distribution:
>>>>> Michael Rice <mpr@absoft.com> writes:
> "tree.h", line 56.1: 1540-222: (S) "rb_tree<char,pair<const char,int>,select1st<pair<const char,int>,char>,less<char> >::rb_tree_node" needs a constructor because class member "value_field" needs a constructor initializer.
> "mm.C", line 14.1: 1540-207: (I) The previous message applies to the definition of template "map<char,int,less<char> >".
> The error seems reasonable to me, and goes away if pair has a default
> constructor.
No, it isn't reasonable, because rb_tree_node is an aggregate. As such, it
can be initialized with a bracketed initializer list instead of a
constructor.
Jason
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: "Michael Rice" <mpr@absoft.com>
Date: 1995/08/24 Raw View
Distribution:
I can't seem to get the map class to compile in the July 7, 1995
version of STL using xlC. This compiler hasn't had any other trouble
compiling it yet.
For the following:
int main ()
{
typedef map<char, int, less<char> > maptype;
maptype m;
return 0;
}
The error message is this:
"tree.h", line 56.1: 1540-222: (S) "rb_tree<char,pair<const char,int>,select1st<pair<const char,int>,char>,less<char> >::rb_tree_node" needs a constructor because class member "value_field" needs a constructor initializer.
"mm.C", line 14.1: 1540-207: (I) The previous message applies to the definition of template "map<char,int,less<char> >".
The error seems reasonable to me, and goes away if pair has a default
constructor. Why doesn't pair have a default constructor anyway? Some
functions return pairs, so people would probably want to write code
like this:
void func() {
pair<type1, type2> pp; // illegal without a def. constructor?
// do something
pp = s.insert(x);
}
Also according to the draft standard, who is wrong here, the compiler or
STL? And this stuff is supposed to work with xlC isn't it or it this one
of those "corner cases"?
--
Mike Rice Absoft Corporation
mpr@absoft.com (810) 853-0050
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]