is there a way to make this code work as intended?
#include <iostream>
using namespace std;
template<typename T> class templated{
public:
static void f(){
cout<<"doing something generically"<<endl;
}
};
template<> class templated<int>{
public:
static void g(){
cout<<"doing something else, but specific to int"<<endl;
f();
}
};
int main(){
templated<int>::g();
}
G++ complains that f is not declared in scope. I have tried all the possible variations in calling f() (templated<int>::f(), putting a dummy declaration in templated, move the declaration outside of class definition…), all of which failed, so I’ll omit them here.
No, a specialization is totally separate from the base template and doesn’t “inherit” anything from it.
Perhaps you can add a free function that can be called from everywhere?