"terminator" <fa***********@gmail.comwrote in message
news:11*********************@r34g2000hsd.googlegro ups.com...
On Jul 20, 7:03 pm, "Fred Kleinschmidt"
<fred.l.kleinmschm...@boeing.comwrote:
>I have a template::
template <class Vclass Vct {
public:
Vct(V);
};
template <class V>
Vct<V>::Vct( V vin ) {
/*...*/
}
Now I would like to add a copy constructor that
takes as its input any arbitrary instance of a Vct<something>.
For example,
double d = 0.0;
int i = 0;
Vct<double x ( d );
Vct<int iy( i );
/* Now I want to make a (double) copy of iy */
Vct<double z( iy );
/* ... and a (int) copy of x*/
Vct<int im( x);
Can it be done? How do I define such a constructor
as a template?
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing
just nest a template in your template:
template <class Vclass Vct {
public:
Vct(const V&);
Vct(const Vct& v){/*and go on*/};
template <class Init>//copy ctor:
Vct(const Vct<Init>& init){/*and go on*/};
//assignment:
const Vct& operator=(const Vct& v){/*and go on*/return *this;};
template <class Assign>
const Vct& operator=(const Vct<Assign>& assign){/*and go on*/
return *this;};
};
Actually, what I have is slightly more complex. It's not really
a true copy constructor I need, since there are other parameters.
The constructor has 3 parameters;
Vct(const Vct&, int, int)
for various types of Vct<xxx>
I also want constructors passing primitive arrays:
Vct( const double *, int, int)
Vct(const float *, int, int)
... etc., plus int*, long*, long long*, etc.
And one that I can take a single variable instead of an array:
Vct( const double, int, int)
Vct(const float, int, int)
... etc., plus int, long, long long, etc.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Aero Stability and Controls Computing