Re: Why can't the linker find the definitions?

From: E. Robert Tisdale (E.Robert.Tisdale_at_jpl.nasa.gov)
Date: 09/22/04

  • Next message: Rohan Seth: "Re: Issue with CODE !!"
    Date: Tue, 21 Sep 2004 17:08:28 -0700
    
    

    William Payne wrote:

    > For some reason, I thought that any function defined in the header file
    > would be inlined automatically

    And, depending upon the implementation, that may be just what happens.

    > and that I could use the keyword inline to request
    > functions defined in the implementation file (cpp-file) to be
    > inlined as well, provided they were short enough.

    Some compilers do look for function definitions
    in other translation units and inline them automatically.
    That' one reason why inline function definitions
    should be the same in *all* translation units.

    > So, if I want to request a
    > function to be inlined, it must be defined in the header?
    > Inside the class declaration itself?

    If you define the function inside the class definition,
    it is an inline function.

    > Or can it be outside (but still in the header)?

    You must *declare* the function in the class definition
    then use the 'inline' qualifier when you define the function
    outside of the class definition.
    Remember to define the inline function
    *before* you invoke it or it will be inline'd
    and your link editor may complain about "undefined references".


  • Next message: Rohan Seth: "Re: Issue with CODE !!"

    Relevant Pages


    Loading