What am I doing wrong in the following code?
I get the following error using gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3:
||=== Build: Debug in TemplateSpecialization (compiler: GNU GCC Compiler) ===|
/home/bp/projects/TemplateSpecialization/TemplateSpecialization/main.cpp|13|error: ‘xyz’ is not a template|
/home/bp/projects/TemplateSpecialization/TemplateSpecialization/main.cpp|13|error: explicit specialization of non-template ‘xyz’|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
I get the following error using gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3:
||=== Build: Debug in TemplateSpecialization (compiler: GNU GCC Compiler) ===|
/home/bp/projects/TemplateSpecialization/TemplateSpecialization/main.cpp|13|error: ‘xyz’ is not a template|
/home/bp/projects/TemplateSpecialization/TemplateSpecialization/main.cpp|13|error: explicit specialization of non-template ‘xyz’|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Code:
#include <iostream>
using namespace std;
template <class T>
class genericType
{
public:
genericType(T x){
cout << x << " is not a character!" << endl;}
};
template<>
class xyz <char>{
public: xyz(char x){
cout << x << " is a character." << endl;}
};
int main()
{
genericType<int> intType(6);
genericType<double> doubleType(65.7);
//xyz<char> charType('Q');
return 0;
}
Last edited: