hi, all
Suppose I have a template class A
template<class Tclass A{
T a;
A(T &a){this->a = a;} //***
}
Then I declare something as following in a header file
A<intabc;
A<int*p;
In somewhere in the cpp file, I'll need to re-initialize them, but not
sure I am doing it correctly.
p = new A<int>(123); //looks fine?
How can I re-initialize abc?
If I'll need other type (double, short, etc) in the runtime, I have to
declare A<double>, A<shortfor each of them in the header file? That
looks like redundant. Thanks for comments.
BTW, in ***, if I write in that way, will the instance of A keeps a
"hard copy" of a such that A keeps what every transfered to a during
initialization from outside even after the outside object is deleted
afterwards? Or maybe I should write A(T a){this->a = a;}?
zl2k
Suppose I have a template class A
template<class Tclass A{
T a;
A(T &a){this->a = a;} //***
}
Then I declare something as following in a header file
A<intabc;
A<int*p;
In somewhere in the cpp file, I'll need to re-initialize them, but not
sure I am doing it correctly.
p = new A<int>(123); //looks fine?
How can I re-initialize abc?
If I'll need other type (double, short, etc) in the runtime, I have to
declare A<double>, A<shortfor each of them in the header file? That
looks like redundant. Thanks for comments.
BTW, in ***, if I write in that way, will the instance of A keeps a
"hard copy" of a such that A keeps what every transfered to a during
initialization from outside even after the outside object is deleted
afterwards? Or maybe I should write A(T a){this->a = a;}?
zl2k
Comment