Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7644645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:44:25+00:00 2026-05-31T09:44:25+00:00

I think my question has been asked here before, I did read them but

  • 0

I think my question has been asked here before, I did read them but still little confused and therefore asking to make it clear.

The C++ standard says all member functions defined inside class definition are inline

I have also heard that compiler can ignore inlining of a function. Will that be true in the above case or it will be always inlined if defined inside class definition?

Also, what was the reason behind this design, making all functions defined inside class definition inline? And what inlining has to do with source and header files?

Update: So one should always define their functions outside class if not to be inlined, right?

Update 2 by JohnB: Two functions declared inside class definition could never call each other as they would have to each contain the whole body of the other function. What will happen in this case? (Already answered by Emilio Garavaglia)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:44:26+00:00Added an answer on May 31, 2026 at 9:44 am

    Confusion arises because inline has two effects:

    1. It tells the compiler that the function code can be expanded where the function is called, instead of effectively being called.
    2. It tells the compiler that the function definition can be repeated.

    Point 1. is “archaic” in the sense that the compiler can in fact do what it likes in order to optimize code. It will always “inline” machine code if it can and find convenient to do and it will never do that if it cannot.

    Point 2. is the actual meaning of the term: if you define (specify the body) a function in the header, since a header can be included in more sources, you must tell the compiler to inform the linker about the definition duplicates, so that they can be merged.

    Now, by the language specification, free functions (not defined in class bodies) are by default not defined as inline, so defining in a header a thing like

    void myfunc()
    {}
    

    if the header is included in more sources, then linked in a same output, the linker will report a multiple definition error, hence the need to define it as

    inline void fn()
    {}
    

    For class members, the default is the opposite: if you just declare them, they will not be inlined. If you define them, they will be inline.

    So a header should look like

    //header file
    
    class myclass
    {
    public:
        void fn1()
        {} //defined into the class, so inlined by default
    
        void fn2();
    };
    
    inline void myclass::fn2()
    {} //defined outside the class, so explicit inline is needed
    

    And if myclass::fn2() definition goes into a proper source, must lose the inline keyword.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked here before, but I don't think those
I don't think this question has been asked before. I'm a bit confused on
I know this sort of question has been asked before , but I still
I know this is a question that has been asked before, but I think
i know this question has been asked here but i am stuck with this
This question has been asked on here a few times, but none of the
I know this question has been asked a bit before. But looking around I
You're probably thinking this has been asked a million times before but I think
I know this question has been asked so many times before but I couldn't
I know this question has been asked and answered before, but none of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.