how to understand "u_long operator() (const KeyType kt) const"

Discussion in 'C++' started by thomas, Feb 14, 2008.

  1. thomas

    thomas Guest

    any ideas for this one?

    --code--
    template<>
    class ACE_Hash<KeyType>
    {
    public:
    u_long operator() (const KeyType kt) const
    {
    int val = kt;
    return (u_long)val;
    }
    };
    --code--

    while "operator u_long (void) const; " may be easily understood as a
    conversion operator;
    what does "u_long operator() (const KeyType kt) const;" mean?
    thomas, Feb 14, 2008
    #1
    1. Advertising

  2. * thomas:
    > any ideas for this one?
    >
    > --code--
    > template<>
    > class ACE_Hash<KeyType>
    > {
    > public:
    > u_long operator() (const KeyType kt) const
    > {
    > int val = kt;
    > return (u_long)val;
    > }
    > };
    > --code--
    >
    > while "operator u_long (void) const; " may be easily understood as a
    > conversion operator;
    > what does "u_long operator() (const KeyType kt) const;" mean?


    'operator()' is the function call operator.

    Given


    KeyType const key = ...;
    ACE_Hash<KeyType> hash;

    you can use the hash object as a function

    u_long const x = hash( key );

    in order to obtain the result of first converting key to int and then
    further to u_long, whatever that type is.


    Cheers, & hth.,

    - Alf

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Feb 14, 2008
    #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. walala
    Replies:
    6
    Views:
    1,740
    Marcus Harnisch
    Sep 3, 2003
  2. Neil
    Replies:
    11
    Views:
    8,536
    vipinlal
    Mar 11, 2010
  3. Rob Meade

    Newbie fails to understand code....

    Rob Meade, Nov 18, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    862
    Rob Meade
    Nov 19, 2003
  4. Paul K

    Trying to understand...

    Paul K, Nov 19, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    340
    Paul K
    Nov 19, 2003
  5. Ketul Patel
    Replies:
    1
    Views:
    717
    Alvin Bruney
    Nov 29, 2003
Loading...

Share This Page