[Dev-C++] Errors: template-id in the declaration of primary template
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Edward H. <hyl...@gm...> - 2007-09-01 16:00:56
|
hi,everyone. today, i wrote a program to test the function template.
When i complided the program, it gave the errrors:
spec.cpp:19: template-id `bytes<wchar_t*>' in declaration of
primary template.
After searching the network, i have no idea about this error.
my g++ version is 3.22
the source code is here:
//: spec.cpp
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
template<class T>
size_t bytes(T& t){
cout << "(using primary template)\n";
return sizeof t;
}
size_t bytes(char*& s){
cout << "using char* overload)\n";
return strlen(s) + 1;
}
size_t bytes<wchar_t *>(wchar_t*& w){
cout << "(using wchar_t* specialization)\n";
return 2*(wcslen(w)+1);
}
}
template<>
size_t bytes<>(string& s){
cout << "(using string explicit specialization)\n";
return sizeof s;
}
template<>
size_t bytes<float>(float& x){
cout << "(using float specialization)\n";
return sizeof x;
}
int main(){
int i;
cout << "bytes in i: " << bytes(i) << endl;
char *s = "hello";
cout << "bytes in s: " << bytes(s) << endl;
wchar_t *w = L"goodbye";
cout << "bytes in w: " << bytes(w) << endl;
string t;
cout << "bytes in w: " << bytes(w) << endl;
string t;
cout << "bytes in t: " << bytes(t) << endl;
float x;
cout << "bytes in x: " << bytes(x) << endl;
double y;
cout << "bytes in y: " << bytes(y) << endl;
return 0;
}
~
thanks for your help!
|