S
slurper
hi,
i'm studying some stl. i saw the pair implementation in a header-file but
what i wonder is if a struct can have constructors as it seems in following
snippet from the stl library. the snippets i wonder about are indicated
with --------> : i thought a struct doesn't have constructors (but here
there are four, actually three)
template <class _T1, class _T2>
struct pair {
typedef _T1 first_type;
typedef _T2 second_type;
_T1 first;
_T2 second;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
---------> pair() : first(), second() {}
#else
---------> pair() : first(_T1()), second(_T2()) {}
#endif
---------> pair(const _T1& __a, const _T2& __b) : first(__a), second(__b)
{}
template <class _U1, class _U2>
--------> pair(const pair<_U1, _U2>& __p) : first(__p.first),
second(__p.second) {}
};
i'm studying some stl. i saw the pair implementation in a header-file but
what i wonder is if a struct can have constructors as it seems in following
snippet from the stl library. the snippets i wonder about are indicated
with --------> : i thought a struct doesn't have constructors (but here
there are four, actually three)
template <class _T1, class _T2>
struct pair {
typedef _T1 first_type;
typedef _T2 second_type;
_T1 first;
_T2 second;
#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
---------> pair() : first(), second() {}
#else
---------> pair() : first(_T1()), second(_T2()) {}
#endif
---------> pair(const _T1& __a, const _T2& __b) : first(__a), second(__b)
{}
template <class _U1, class _U2>
--------> pair(const pair<_U1, _U2>& __p) : first(__p.first),
second(__p.second) {}
};