3 ms·
I replied to this not knowing exactly where the goalposts are. Indeed, in C++, our a + b expression is statically analyzed to be working with specific types; t
by kazinator 2y ago
I replied to this not knowing exactly where the goalposts are.
Indeed, in C++, our a + b expression is statically analyzed to be working with specific types; the declared types of a and b. When that code is compiled, it will work with no other types.
However, if we anticipate that kind of extension, we can have a be a reference to some numeric_base class where operator + is a virtual function.
With some help from a bit of platform specific coding, we can have dynamically loaded modules which can provide new classes derived from numeric_base that ca be passed to existing code in the program which uses + on numeric_base.