in-class function definitions, inline

Discussion in 'C++' started by Hicham Mouline, Jan 31, 2008.

  1. hi,

    I include a header file from 2 translation units. In this header file , I
    have a "policy" class with only static member functions:

    class C {
    static double f1() { return 6.0; }
    static bool f2() { return true; }
    };

    I would like to hint to the compiler to inline these functions.
    I think i have read somewhere that functions defined in-class are
    automatically hinted as inline... And i don't need to add the "inline"
    keyword, and that i should add inline when the functions are defined
    out-of-class, as:

    class C {
    static double f1();
    static bool f2();
    };
    inline double C::f1()
    {
    return 6.0;
    }
    inline double C::f2()
    {
    return true;
    }

    regards,
     
    Hicham Mouline, Jan 31, 2008
    #1
    1. Advertising

  2. * Hicham Mouline:
    > hi,
    >
    > I include a header file from 2 translation units. In this header file , I
    > have a "policy" class with only static member functions:
    >
    > class C {
    > static double f1() { return 6.0; }
    > static bool f2() { return true; }
    > };
    >
    > I would like to hint to the compiler to inline these functions.
    > I think i have read somewhere that functions defined in-class are
    > automatically hinted as inline...


    Not exactly. When they're defined in-class they are defined inline.
    And the effect is as if you had used the keyword "inline", which permits
    equivalent definitions in other translation units, i.e., from a
    practical point of view, permits the definitions to be in a header file.

    The hinting about inline code generation comes on top of that, it's an
    /additional/ but not very important effect of keyword "inline".


    > And i don't need to add the "inline"
    > keyword, and that i should add inline when the functions are defined
    > out-of-class, as:
    >
    > class C {
    > static double f1();
    > static bool f2();
    > };
    > inline double C::f1()
    > {
    > return 6.0;
    > }
    > inline double C::f2()
    > {
    > return true;
    > }


    If this is code in a header file, yes.


    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, Jan 31, 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. Nish
    Replies:
    4
    Views:
    526
    Thomas Stegen
    Oct 8, 2004
  2. TGOS
    Replies:
    3
    Views:
    396
    Kevin Bracey
    Feb 28, 2005
  3. Ajay
    Replies:
    5
    Views:
    412
    Pete Becker
    Apr 1, 2006
  4. Replies:
    7
    Views:
    457
  5. Replies:
    2
    Views:
    367
Loading...

Share This Page