News for hackers. Stuff that matters.
Re:Inheritance Often Doesn't Make Sense by andrewflnr on Saturday March 17, 2018 @11:37PM (#16610374)
Structures of function pointers and, what, string method names? My C++ is rusty, but that's all I can think of. I guess there's a lot of variations on structures of pointers...
Re:Inheritance Often Doesn't Make Sense by nostrademons on Sunday March 18, 2018 @02:13AM (#16610669)
Templates and compile-time polymorphism. This is what the STL is based upon. A forward iterator is any type for which the * and ++ operators are defined; you can use it in any template that makes use of just those syntactic forms, but will get a compiler error if you try to instantiate a template with a type that does not support those operators.

Punning on memory layouts, a la PyObject_HEAD or some of the objects in V8. With this approach, you make sure that all related types have the same memory layout for a subset of fields at the beginning of the struct. Then, a reinterpret_cast on a pointer to one member of the type will yield the same values as a different member of the type, and so can be used generically by code that depends only upon those members. (You have to be very careful with this approach, because multiple inheritance and vtables will usually break it, but if you absolutely positively must have zero-overhead runtime polymorphism it's occasionally the best option.)

#include and preprocessor magic to redefine symbols based on preprocessor defines. Used to be the old way to swap out different implementations of a cross-platform interface, but seems to have largely fallen out of favor in the last couple decades.

Linker magic to accomplish the same, where the header file defines a common interface but the linker may link with one of several different object files to implement that interface at link time. This one is still fairly commonly used; Google and Facebook both have their own custom STL & libstdc++ implementations, and this is also commonly used to swap out eg. malloc implementations.

dlopen & dlsym to do this at runtime. Header file defines the interface, dlsym gives you back a function pointer or set thereof for a plugin implementation.

Re:Inheritance Often Doesn't Make Sense by stephen_gareth on Sunday March 18, 2018 @03:59PM (#16613943)
In Sean Parent's 'Inheritance is the base class of evil' talk Sean outlines an interesting way to achieve runtime polymorphism without inheriting interfaces in C++.

https://www.youtube.com/watch?v=bIhUE5uUFOA

Re:Inheritance Often Doesn't Make Sense by Paul_Dirac on Monday March 19, 2018 @07:24AM (#16617596)
But he uses interface inheritance.

You see it at 9:44. Where he creates the concept_t and int_model_t inherits from it.

Re:Inheritance Often Doesn't Make Sense by stephen_gareth on Wednesday March 21, 2018 @03:50PM (#16641674)
Indeed. But the original type isn't 'burdened' with the interface. I've used the technique for a simple audio signal processing chain.