C
cinsk
hi.
I just read the definition of the std:air in <utility>. std:air
has following two copy constructors:
template <class T1, class T2>
struct pair {
pair:air(const pair &);
template<class U1, class U2> pair:air(const pair<U1, U2> &);
...
};
The definition of both copy constructor looks same in my gentoo Linux/
gcc 4.4.3.
Although I'm not good at template, both copy constructors look same to
me.
Q1. What is the purpose of the second copy constructor?
Could you give me some short example code that actually calls
the second copy constructor?
Q2. What happen if the second copy construct is missing?
Q3. How can the compiler determine which copy constructor is used?
In my poor understanding, it looks like that compile would
complain for the ambiguity.
Q4. If I want to make a template class, do I need to provide both copy
constructor?
If not, which is better? And why?
Thank you.
I just read the definition of the std:air in <utility>. std:air
has following two copy constructors:
template <class T1, class T2>
struct pair {
pair:air(const pair &);
template<class U1, class U2> pair:air(const pair<U1, U2> &);
...
};
The definition of both copy constructor looks same in my gentoo Linux/
gcc 4.4.3.
Although I'm not good at template, both copy constructors look same to
me.
Q1. What is the purpose of the second copy constructor?
Could you give me some short example code that actually calls
the second copy constructor?
Q2. What happen if the second copy construct is missing?
Q3. How can the compiler determine which copy constructor is used?
In my poor understanding, it looks like that compile would
complain for the ambiguity.
Q4. If I want to make a template class, do I need to provide both copy
constructor?
If not, which is better? And why?
Thank you.