#include <iostream>
#include <string>
using namespace std;
struct Uid {
typedef int type;
};
struct Name {
typedef string type;
};
struct Age {
typedef int type;
};
template <class T1, class T2, class T3>
class People {
private:
typename T1::type val1;
typename T2::type val2;
typename T3::type val3;
//add a get function here
}
};
int main() {
People<Uid, Name, Age> people;
people.get<Uid>(); //make this validate
}
this is my code, and I want to add a get function in the class to make the function call get in main validate.
I try to add a tempalte get and its specialization version in the class, but it’s an invalidate methond, the complier said: explicit specialization in non-namespace scope ‘class People’. Someone said this method works in vs, but it break the standard.
You need a helper class that your templated get() member function can use. The helper class can be at namespace scope.