- 1

Need explanation for this code -URGENT

#include <bits/stdc++.h>> template <typename T>class Array { private: T* ptr; int size; public: Array(T arr[],int s); void print(); }; template <typename T> Array<T>::Array(T arr[],int s) { ptr=new T[s]; size=s; for(int i=0;i<size;i++) ptr[i]=arr[i]; } template <typename T> void Array<T>::print() { for(int i=0;i<size;i++) std::cout<<" "<<*(ptr+i); std::cout<<std::endl; } int main() { int arr[5]={1,2,3,4,5}; Array<int>a(arr,5); a.print(); return 0; }

23rd May 2022, 6:04 PM
Muskan Singh
Muskan Singh - avatar
2 Answers
+ 4
If it's urgent you should have started doing your homework earlier.
23rd May 2022, 6:44 PM
Simon Sauter
Simon Sauter - avatar
+ 3
People are much more likely to look at your code if you put it in a script on sololearn playground. Go to Code section, click +, select the programming language, insert your code, save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
23rd May 2022, 6:21 PM
Lisa
Lisa - avatar