I am trying to initialize my template class with a type alias as template parameter, but only the specialized version of my class is created. I understand the problem is in the ambiguity of my aliases. Is there a workaround?
#include <iostream>
using Type1 = size_t;
using Type2 = size_t;
template <class Type>
class SomeClass {
public:
void doSomething() {
}
};
template <>
class SomeClass<Type1> {
public:
};
int main() {
SomeClass<Type1> someClass1; // SomeClass<Type1> is initialized
SomeClass<Type2> someClass2; // ... and also SomeClass<Type1> is initialized ???
someClass2.doSomething(); // and therefor doSomething() is not working...
}
What you ask for is not possible. Not directly. Type aliases merely introduce a name that refers to the type. In your code
Type1andType2really are the same type.What you can do: A level of indirection.
And what before used
TypeinSomeClassnow usestypename Type::type. NowSomeClass<Type1>andSomeClass<Type2>are two different instantiations, nevertheless they can use the sametype.