I have a template class with an overloaded + operator. This is working fine when I am adding two ints or two doubles. How do I get it to add and int and a double and return th
This is technically possible by defining an implicit case to TemplateTest
:
operator TemplateTest() {
return TemplateTest((double)x);
}
Practically this probably isn't a great idea though, as x
can't necessarily be safely cast to a double; it happens that you're using a TemplateTest
here, but you could be using a TemplateTest
later. You should probably rethink what you're doing and decide if you're sure you actually need this behavior