Thread View: comp.std.c++
2 messages
2 total messages
Started by Michael Rice
Thu, 24 Aug 1995 20:26
STL map and pair classes
Author: Michael Rice
Date: Thu, 24 Aug 1995 20:26
Date: Thu, 24 Aug 1995 20:26
44 lines
1955 bytes
1955 bytes
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. ]
Re: STL map and pair classes
Author: Jason Merrill
Date: Fri, 25 Aug 1995 06:11
Date: Fri, 25 Aug 1995 06:11
20 lines
1303 bytes
1303 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads