The pair Class. McGraw-Hill The Complete Reference Fourth Edition
Реклама
Реклама
930
C + + : T h e C o m p l e t e R e f e r e n c e ptr->f();
} return 0;
The output produced by this program is shown here: constructing
Inside f()
Inside f() destructing
Notice that X's member function f( ) can be called either through an auto_ptr or through the "normal" pointer returned by get( ).
The pair Class
The pair class is used to house pairs of objects, such as might be stored in an associative container. It has this template specification: template <class Ktype, class Vtype> struct pair { typedef Ktype first_type; typedef Vtype second_type;
Ktype first;
Vtype second;
}
// constructors pair(); pair(const Ktype &k, const Vtype &v); template<class A, class B> pair(const<A, B> &ob);
The value in first typically contains a key, and the value in second typically contains the value associated with that key.
The following operators are defined for pair: ==, !=, <, <=, >, and >=.
You can construct a pair using either one of pair's constructors or by using
make_pair( )
, which constructs a pair object based upon the types of the data used as parameters. make_pair( ) is a generic function that has this prototype: template <class Ktype, class Vtype> pair<Ktype, Vtype> make_pair(const Ktype &k, const Vtype &v);
Изтегляне
Реклама