inlined and outlined member functions

This is a discussion on inlined and outlined member functions within the C++ Programming forums, part of the General Programming Boards category; I dunno if there is a typo in my C++ book or not, but I was wondering how a inlined ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,666
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21