c_-_c_templates:default_template_arguments
C - C++ Templates - Default template arguments
#include<iostream> using namespace std; template<class T=int,int size=5> class array { T var[size]; int i; public: array() { for(i=0;i<size;i++) var[i]=i; } void display() { for(i=0;i<size;i++) cout<<var[i]<<"\n"; cout<<"\nSize of variable:"; cout<<sizeof(var); } }; int main() { array<int> a1; array<float,10> a2; cout<<"using int\n"; a1.display(); cout<<"\nusing float\n"; a2.display(); return 0; }
c_-_c_templates/default_template_arguments.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1