Too few template-parameter-lists

Hello there ,
I have been following some online tutorials and got this awesome code.However ,when I tried to implement it myself , I got some errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//Tempate specialization

#include<iostream>
#include<string.h>
using namespace 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 = new char[strlen(name)+1];
 strcpy(m_tvalue,name);
}

//Specialized destructor to avoid memory leak
Storage<char*>::~Storage(){
	delete[] m_tvalue ;
}

int main(){
	char *name = new char[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
You're missing template<> before each specialization.

(Also, you need to declare the destructor if you want to specialize it, and you need to use delete[], not delete to match new[])
Last edited on
Thanks ..that fixed the problem.
Topic archived. No new replies allowed.