dimanche 29 janvier 2017

size of template class

The output of the below code is 16. Why so? even without initializing with the length of array of the class the size is 16 and with initializing the length with the 2nd constructor, it is the same size i.e. 16. Any explanation?

  #include <iostream>
    #include <string>
using namespace std;

template <class T>
class array1{
    T * arr;
    int l;
    public:
    array1(){
        arr = 0; l=0;
        }
    array1(int x){
        l = x;
        arr = new T[l];
    }
    ~array1(){
        delete[] arr;
        }
    void display(){
        cout << "array1 is :"<<endl;
        for (int i=0; i<l; i++)
        cout << arr[i] << " ";
        cout << endl;
    }

};

int main()
{
array1<int> a1;
cout << "size of int arr is " << sizeof(a1);
return 0;
}

Aucun commentaire:

Enregistrer un commentaire