given the following code:
template<class T>
class A{
T* arr;
int size;
public:
A(T* arr, int size);
};
template<class T>
A<T>::A(int size) :
arr(new T[size]), size(size) {
for (int i = 0; i < size; i++) {
arr[i] = T();
}
}
It's ok to initialize the array like that? What in fact happens while I doing arr(new T[size])
, namely, which values will be in the array after this line?
If for example I want to create object from this class (with T=int
) , exists a way to implement the constructor so that I will get in any cell 0
?
Aucun commentaire:
Enregistrer un commentaire