Can I have one member function with two names? Like an Alias?

Discussion in 'C++' started by Tom, Jul 4, 2003.

  1. Tom

    Tom Guest

    class CBlah
    {
    void MemberFun1( int x )
    { ... }
    void MemberFun2( int x )
    { MemberFun1( x ); }
    };

    This doesn't look very efficient to me. Or might the compiler optimize MemberFun2 away? Or is there a better way to do this?

    Thanks,
    Tom.
    Tom, Jul 4, 2003
    #1
    1. Advertising

  2. "Tom" <> wrote in message news:<ME7Na.60561$>...
    > class CBlah
    > {
    > void MemberFun1( int x )
    > { ... }
    > void MemberFun2( int x )
    > { MemberFun1( x ); }
    > };
    >
    > This doesn't look very efficient to me. Or might the compiler optimize
    > MemberFun2 away? Or is there a better way to do this?


    By writing the code within the class, you instruct the compiler to
    "inline" the code for MemberFun1. Given its complexity, this is
    likely to succeed. In debug mode, this often will be ignored though,
    so you can fllow the code through MemberFun2

    From an interface viewpoint, the second function doesn't add value
    - although a real-world example might, with e.g. arguments
    exchanged.

    Regards,
    --
    Michiel Salters
    Michiel Salters, Jul 4, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JustSomeGuy

    Can one class have two names?

    JustSomeGuy, Dec 12, 2003, in forum: C++
    Replies:
    9
    Views:
    492
    Risto Lankinen
    Dec 16, 2003
  2. Ares Lagae
    Replies:
    8
    Views:
    448
    Ares Lagae
    Sep 24, 2004
  3. mark4asp
    Replies:
    2
    Views:
    619
    Jasbird
    Nov 11, 2006
  4. =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B

    Does python have the static function member like C++

    =?utf-8?B?5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B, Apr 11, 2007, in forum: Python
    Replies:
    9
    Views:
    322
    goodwolf
    Apr 11, 2007
  5. grocery_stocker
    Replies:
    9
    Views:
    755
    grocery_stocker
    May 24, 2008
Loading...

Share This Page