Click here to Skip to main content
15,884,472 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Absolutely Horrific Pin
Daniel Pfeffer18-Mar-21 7:43
professionalDaniel Pfeffer18-Mar-21 7:43 
GeneralRe: Absolutely Horrific Pin
Slow Eddie20-Mar-21 2:53
professionalSlow Eddie20-Mar-21 2:53 
GeneralRe: Absolutely Horrific Pin
Greg Utas18-Mar-21 8:17
professionalGreg Utas18-Mar-21 8:17 
GeneralRe: Absolutely Horrific Pin
obermd19-Mar-21 3:46
obermd19-Mar-21 3:46 
GeneralRe: Absolutely Horrific Pin
Greg Utas19-Mar-21 4:26
professionalGreg Utas19-Mar-21 4:26 
GeneralRe: Absolutely Horrific Pin
honey the codewitch27-Mar-21 12:43
mvahoney the codewitch27-Mar-21 12:43 
GeneralRe: Absolutely Horrific Pin
Greg Utas27-Mar-21 14:27
professionalGreg Utas27-Mar-21 14:27 
GeneralRe: Absolutely Horrific Pin
honey the codewitch27-Mar-21 15:25
mvahoney the codewitch27-Mar-21 15:25 
Greg Utas wrote:
Never heard of source level as an adjective for polymorphism. What's it mean?


It means if I have a template

C++
template<typename T> struct A { 
    T t; 
    A() : t() { t.foo(); }
};


Then this will compile
C++
struct B {
   void foo() { printf("hello!\r\n"); }
};

A<B> c;


but this won't:

C++
struct B {
   void bar() { printf("goodbye!\r\n"); }
};

A<B> c;


template A will take any class "of a type" that exposes a public foo() method.

This allows you to create a kind of polymorphism at the source level. There is no explicit binary contract like there is with traditional polymorphism. It's a source contract. You don't actually need a binary interface to be fulfilled for the class.

The bottom line is, you don't inherit to do it. You just call the methods you need. It works because templates aren't resolved until they are instantiated.

One of the chief advantages of this over traditional inheritance based polymorphism is that there's no source dependency on a base class. Most of the STL does it this way, preventing much of the cross header dependencies that would otherwise be needed

Greg Utas wrote:
By this, do you mean that code that isn't used doesn't get linked into the .exe?


Yes. I don't know if there's a better name for it, that's just what i've always called it. It's so critical for so much of what i do in C++. My code I'm writing would be so not viable without it.
Real programmers use butterflies


modified 27-Mar-21 21:38pm.

GeneralRe: Absolutely Horrific Pin
Greg Utas27-Mar-21 15:47
professionalGreg Utas27-Mar-21 15:47 
GeneralRe: Absolutely Horrific Pin
honey the codewitch27-Mar-21 15:49
mvahoney the codewitch27-Mar-21 15:49 
GeneralRe: Absolutely Horrific Pin
honey the codewitch27-Mar-21 15:39
mvahoney the codewitch27-Mar-21 15:39 
GeneralRe: Absolutely Horrific Pin
Greg Utas27-Mar-21 15:48
professionalGreg Utas27-Mar-21 15:48 
RantRe: Absolutely Horrific Pin
Daniel Pfeffer18-Mar-21 7:45
professionalDaniel Pfeffer18-Mar-21 7:45 
GeneralRe: Absolutely Horrific Pin
OriginalGriff18-Mar-21 21:53
mveOriginalGriff18-Mar-21 21:53 
GeneralRe: Absolutely Horrific Pin
Rick York19-Mar-21 5:49
mveRick York19-Mar-21 5:49 
GeneralRe: Absolutely Horrific Pin
jlongo19-Mar-21 11:37
jlongo19-Mar-21 11:37 
GeneralRe: Absolutely Horrific Pin
István Smrtnik27-May-21 1:46
István Smrtnik27-May-21 1:46 
GeneralWeird but not Wonderful - .Net Core project discovery Pin
#realJSOP22-Feb-21 1:17
mve#realJSOP22-Feb-21 1:17 
GeneralRe: Weird but not Wonderful - .Net Core project discovery Pin
raddevus22-Feb-21 2:35
mvaraddevus22-Feb-21 2:35 
GeneralRe: Weird but not Wonderful - .Net Core project discovery Pin
#realJSOP22-Feb-21 3:00
mve#realJSOP22-Feb-21 3:00 
GeneralRe: Weird but not Wonderful - .Net Core project discovery Pin
raddevus22-Feb-21 3:46
mvaraddevus22-Feb-21 3:46 
GeneralRe: Weird but not Wonderful - .Net Core project discovery Pin
#realJSOP22-Feb-21 3:48
mve#realJSOP22-Feb-21 3:48 
GeneralRe: Weird but not Wonderful - .Net Core project discovery Pin
raddevus23-Feb-21 3:30
mvaraddevus23-Feb-21 3:30 
GeneralRe: Weird but not Wonderful - .Net Core project discovery Pin
Gary R. Wheeler7-Mar-21 8:23
Gary R. Wheeler7-Mar-21 8:23 
GeneralRe: Weird but not Wonderful - .Net Core project discovery Pin
kapalmuks<329-Aug-21 12:15
kapalmuks<329-Aug-21 12:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.