The error
User-defined conversion must convert to or from the enclosing type.
means that your conversion operators need to convert to/from A<T>
. Yours are converting to/from A<int/string>
. That's not the same thing (much less general at least).
So this cannot work. You have to find some other way to do the conversions. Maybe runtime casting can help here (define the operators as acting on A<T>
and do casting inside of them).
I think this problem is unrelated to the type synonyms. In fact they made the question harder to understand.