Thread: inlined and outlined member functions

  1. #1
    lv.42 Berserker Drake's Avatar
    Join Date
    Jun 2005
    Posts
    67

    Question inlined and outlined member functions

    I dunno if there is a typo in my C++ book or not, but I was wondering how a inlined and outlined function would be declared and defined in a class. If possible, put why it is good to inline and outline functions and why it's not.

    Thanks.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Inline functions are good for performance reasons, normally when you call a function a jump occurs in the code which creates some [minor] ovehead. Inlining is good when the function is trivial (one liners, getters, setters, etc.), or it can be good if you have performance problems. Lastly, the compiler may not inline your method, it may put in code for a function call anyway.

    You can do inlining nice like this:
    Code:
    class X {
    public:
        void foo( );
    };
    
    inline void X::foo( ) {
        cout << "hello from foo\n";
    }
    Any function not inlined is "outlined" I suppose.

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

Popular pages Recent additions subscribe to a feed