4 ms·
> functions can be written to extend it. Unless I'm mistaken (which I may well be), you can't do that at runtime, only at compile time.
by Turing_Machine 2y ago
> functions can be written to extend it.
Unless I'm mistaken (which I may well be), you can't do that at runtime, only at compile time.
- kazinator 2y agoI 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.