I would like define my template specialization in the .cpp
file and not in .h
file. Is there a way I can do this?
I am using the g++ compiler
//main.cpp
#include <iostream>
#include <string>
#include "People.cpp"
using namespace std;
int main() {
Spunky <int> obj3(1);
Spunky<char>obj2('y');
return 0;
}
//People.cpp
#include <iostream>
#include "People.h"
using namespace std;
// TEMPLATE SPECIALISATION
template < class T>
Spunky <T>:: Spunky( T x){
cout << x << " is not a character ! " << endl;
}
template <>
Spunky:: Spunky<char> ( char x ) {
cout << x << " is indeed a character"<< endl;
}
//People.h
#ifndef PEOPLE_H
#define PEOPLE_H
using namespace std;
// TEMPLATE SPECIALISATIONS
template < class T>
class Spunky{
public:
Spunky ( T x) ;
};
template <>
class Spunky <char> {
public:
Spunky (char x);
// { cout<< x << "is indeed a character"<<endl; }
};
#endif
compiler error is:
template argument deduction is only available with -stdC==1z or -std=gnu++1z
How can I go about fixing this?