Is it somehow possible to have callable, non-templated functions in a templated class? Like so:
template<typename T>
class Object
{
public:
static int loadInfo() { return 0;}
// more code
};
I'd like to write, e.g.:
Object::loadInfo();
instead of
Object<int8_t>::loadInfo();
It's not virtually important, would just be some 'syntactic sugar'. A bit more background: the function I am thinking of would load some data from disk upon which the program decides which templated version of the object it has to use. ATM it looks like this:
auto usewhat=Object<char>::loadInfo(); // this line feels so wrong
if(usewhat == 0) {
Object<int8_t> o;
o.doSomething();
}else if(usewhat == 1){
Object<int32_t> o;
o.doSomething();
}else{
Object<int64_t> o;
o.doSomething();
}
The only possibilities I can think of atm are 1) using a non-template base class of a different name (say, "BaseObject") or 2) using another class with a different name (say, "InfoObject") ... but both possibilities do not seem too appealing.