'inline' during declaration & definition

Discussion in 'C++' started by qazmlp, Jul 30, 2003.

  1. qazmlp

    qazmlp Guest

    // test.h
    class test
    {
    public :
    inline void check() ;

    } ;

    // test.C
    inline void test::check() // Is 'inline' optional here?
    {

    }


    Do I need to use 'inline' keyword again in the prototype in .C file
    when it is already given as 'inline' in the .h file?.
    qazmlp, Jul 30, 2003
    #1
    1. Advertising

  2. qazmlp

    ES Kim Guest

    "qazmlp" <> wrote in message
    news:...
    > // test.h
    > class test
    > {
    > public :
    > inline void check() ;
    >
    > } ;
    >
    > // test.C
    > inline void test::check() // Is 'inline' optional here?
    > {
    >
    > }
    >
    >
    > Do I need to use 'inline' keyword again in the prototype in .C file
    > when it is already given as 'inline' in the .h file?.


    No, you don't have to, but definition of the inline function should be
    known in the source file where it is called so that the function body
    can be inserted in hard-coded way. A common practice is to define
    the function in class definition block of header file. That way, all the
    sources including the header will know the definition of the function.
    It's just "in a line" anyway.

    class test
    {
    public:
    void check() { /* do something */ } // inline keyword is not necessary
    };

    --
    ES Kim
    ES Kim, Jul 30, 2003
    #2
    1. Advertising

  3. qazmlp

    Greg Comeau Guest

    In article <>,
    qazmlp <> wrote:
    >// test.h
    >class test
    >{
    > public :
    > inline void check() ;
    >
    >} ;
    >
    >// test.C
    >inline void test::check() // Is 'inline' optional here?
    >{
    >
    >}
    >
    >
    >Do I need to use 'inline' keyword again in the prototype in .C file
    >when it is already given as 'inline' in the .h file?.


    It's up to you.

    But:
    Normally you wouldn't use inline in the prototype in a .C file
    because normally your inline would be in a .h file.

    Also, adding inline to a definition to a function that is only
    provided in a non-.h file and is expect to be used by other
    non-.h source files usually will not obtain inline'ability,
    since many compilers do not yet support cross translation
    inlining. IOWs, this:

    // file1.cpp

    // ....
    void inline foo()
    {
    ...
    }



    //file2.cpp

    //...
    void bar()
    {
    foo();
    }

    will usually not consider foo as a candidate for inlineing.
    --
    Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
    Greg Comeau, Jul 30, 2003
    #3
    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. Abhi
    Replies:
    2
    Views:
    725
    E. Robert Tisdale
    Jul 3, 2003
  2. Alvin
    Replies:
    7
    Views:
    464
    E. Robert Tisdale
    May 6, 2005
  3. Replies:
    3
    Views:
    447
  4. Daniel Vallstrom
    Replies:
    2
    Views:
    1,830
    Kevin Bracey
    Nov 21, 2003
  5. Nish
    Replies:
    4
    Views:
    479
    Thomas Stegen
    Oct 8, 2004
Loading...

Share This Page