//Tempate specialization
#include<iostream>
#include<string.h>
usingnamespace std;
template <typename T>
class Storage {
private :
T m_tvalue ;
public :
Storage(T tvalue){
m_tvalue = tvalue ;
}
void print(){
cout << m_tvalue << endl;
}
};
//Specialized constructor
Storage<char*>::Storage(char* name){
m_tvalue = newchar[strlen(name)+1];
strcpy(m_tvalue,name);
}
//Specialized destructor to avoid memory leak
Storage<char*>::~Storage(){
delete[] m_tvalue ;
}
int main(){
char *name = newchar[strlen("Raman")+1];
strcpy(name,"Raman");
Storage<char*> strVal(name); //assigning values
delete name ;
strVal.print(); //Now it should print the name
return 0;
}
However, it gives the error too few template-parameter-lists in the specialized constructor and destructor.
Any suggestions will be appreciated..thanks