- 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; }
2 Respostas
+ 4
If it's urgent you should have started doing your homework earlier.
+ 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.