Click here to Skip to main content
15,893,564 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: MQOTD Pin
Corporal Agarn6-Jan-14 2:52
professionalCorporal Agarn6-Jan-14 2:52 
GeneralDuck typing Pin
Marco Bertschi5-Jan-14 20:43
protectorMarco Bertschi5-Jan-14 20:43 
GeneralRe: Duck typing Pin
Kornfeld Eliyahu Peter5-Jan-14 21:11
professionalKornfeld Eliyahu Peter5-Jan-14 21:11 
GeneralRe: Duck typing Pin
Nagy Vilmos5-Jan-14 21:40
professionalNagy Vilmos5-Jan-14 21:40 
GeneralRe: Duck typing Pin
CBadger5-Jan-14 21:40
professionalCBadger5-Jan-14 21:40 
GeneralRe: Duck typing Pin
BillWoodruff5-Jan-14 21:57
professionalBillWoodruff5-Jan-14 21:57 
GeneralRe: Duck typing Pin
Gjeltema6-Jan-14 4:13
Gjeltema6-Jan-14 4:13 
AnswerRe: Duck typing Pin
Pablo Aliskevicius5-Jan-14 22:58
Pablo Aliskevicius5-Jan-14 22:58 
See this:
http://www.google.com/search?q=c%2B%2B+compile+time+polymorphism[^]
For instance, in a C++ template, you can do something like this:

C++
template <class T> class Foo: public T
{
    int Baa(int k)
    {
        T * pT = static_cast<T*>(this); // this is the magic
        return 42 + pT->Baz(k - 3); // for instance. 
    }
};

Any class that exposes a method Baz that returns something that can be converted to an integer, and can be called with an integer parameter, can be a template paremeter for class Foo. No special interfaces required, so it is less restrictive than, for instance, C# generics.
Aside: 'less restrictive' doesn't mean 'better', or 'worse'.
Also, the code above is resolved at compile time, which may have a noticeable impact on performance.

Duck typing is also used in Javascript, for other reasons (mostly, IMHO, flexibility).


JM2B,
Pablo.

"Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).
"You are to act in the light of experience as guided by intelligence" (Rex Stout, "In the Best Families", 1950).

GeneralRe: Duck typing Pin
peterchen6-Jan-14 0:13
peterchen6-Jan-14 0:13 
GeneralRe: Duck typing Pin
Shameel5-Jan-14 23:09
professionalShameel5-Jan-14 23:09 
GeneralRe: Duck typing Pin
John Atten6-Jan-14 4:14
John Atten6-Jan-14 4:14 
GeneralRe: Duck typing Pin
Roger Wright6-Jan-14 8:58
professionalRoger Wright6-Jan-14 8:58 
GeneralSR-71 pron! Get in and take a look around! Pin
Dave Kreskowiak5-Jan-14 8:21
mveDave Kreskowiak5-Jan-14 8:21 
GeneralRe: SR-71 pron! Get in and take a look around! Pin
Mike Hankey5-Jan-14 9:22
mveMike Hankey5-Jan-14 9:22 
GeneralRe: SR-71 pron! Get in and take a look around! Pin
Member 41945935-Jan-14 10:32
Member 41945935-Jan-14 10:32 
General":@#^%^#$ cars Pin
Erudite_Eric5-Jan-14 6:52
Erudite_Eric5-Jan-14 6:52 
GeneralRe: ":@#^%^#$ cars Pin
Ron Anders5-Jan-14 7:56
Ron Anders5-Jan-14 7:56 
GeneralRe: ":@#^%^#$ cars Pin
Chris Maunder5-Jan-14 17:04
cofounderChris Maunder5-Jan-14 17:04 
GeneralRe: ":@#^%^#$ cars Pin
Erudite_Eric5-Jan-14 18:57
Erudite_Eric5-Jan-14 18:57 
GeneralRe: ":@#^%^#$ cars Pin
Chris Maunder6-Jan-14 5:17
cofounderChris Maunder6-Jan-14 5:17 
General5-0 whitewash. Pin
Septimus Hedgehog5-Jan-14 5:20
Septimus Hedgehog5-Jan-14 5:20 
GeneralRe: 5-0 whitewash. Pin
Vikram A Punathambekar5-Jan-14 6:29
Vikram A Punathambekar5-Jan-14 6:29 
GeneralRe: 5-0 whitewash. Pin
Abhinav S5-Jan-14 6:40
Abhinav S5-Jan-14 6:40 
GeneralRe: 5-0 whitewash. Pin
Abhinav S5-Jan-14 6:42
Abhinav S5-Jan-14 6:42 
GeneralRe: 5-0 whitewash. Pin
M-Badger5-Jan-14 9:04
M-Badger5-Jan-14 9:04 

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.