ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Talk:Function pointer - Wikipedia, the free encyclopedia

Talk:Function pointer

From Wikipedia, the free encyclopedia

[edit] Object-oriented equivalent?

Perhaps there could be something here showing how the same thing can be achieved using Object Oriented Programming? Ubermonkey 20:35, 2 Apr 2005 (UTC)

Also a nice implementation of this using a class where the method is passed as a function pointer (so a method pointer i guess). I've been trying to find an example of this everywhere and i can't find it. -Sharth --128.175.13.43 17:54, 26 October 2005 (UTC)

It would also be nice if the program actually worked.. say.. if it had a definition for the "list" or "listnode" types. Fresheneesz 07:56, 5 June 2006 (UTC)

One way to do the equivalent of function pointers in Java is to define an interface with a single method. Then one or more classes can implement the interface, and objects of these class types can be passed to other methods. These interface references act something like method pointers:
public interface Foo
{
    public abstract int perf(int a);
}

class MyFoo implements Foo
{
    public int perf(int a)
    {
        return (2*a + 3);
    }
}

public class Test
{
    static Foo  s_func;

    public static void main(String[] args)
    {
        int x;

        setFunc(new MyFoo());
        x = callFunc(10);
    }

    void setFunc(Foo f)
    {
        s_func = f;
    }

    int callFunc(int a)
    {
        return s_func.perf(a);
    }
}
Loadmaster 01:00, 9 March 2007 (UTC)

[edit] Not using function pointers

"Imagine rewriting the above code without function pointers. The fsum() and fproduct() function would both require loops iterating through the linked list." Isn't it contradicting to say that when the code does exactly that--or am I missing something? Guardian653 03:55, 2 December 2006 (UTC)

Agreed. Seems like the author is not NPOV since he calls it a "clearly" "powerful" mechanism. Using it to obfuscate code is arguably not the best application of this feature. 24.6.99.30 12:50, 3 January 2007 (UTC)


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -