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 519515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:02:56+00:00 2026-05-13T08:02:56+00:00

I am making a Qt application and as I was coding, I took the

  • 0

I am making a Qt application and as I was coding, I took the habit of defining my slots in the header. I found it was easier for me to develop that way though I still define normal functions in the .cpp (unless the function is really small). But now there are some worries from my colleague that putting these in the header is bad practice because the fact of defining them in the header makes them inline so I am looking into the matter to understand everything that is going on. This is the reason I was given:

“Even in-lined functions (other than as required by classes) is a highly debatable practice. In theory, it creates faster, but larger code (avoids function calls and returns by duplicating code). However, several people have noticed that often using in-lining actually creates slower code. The reason why is because it can cause the code to get larger and exceed the size of what fits in one or more caches used at run-time. As a result it causes portions of the function to go in and out of cache every pass through some loop and the cache misses and subsequent reloads are far more costly than a function call to something already in another cache page. It’s an interesting situation and one that can’t be predicted, only observed by trial and error.”

  • 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-13T08:02:57+00:00Added an answer on May 13, 2026 at 8:02 am

    Your colleague needs to check up on the meaning of inlining in C++.

    There are two meanings of the word, and it’s important to keep them separated:

    According to the C++ standard, a function is inline if it is marked with the inline keyword, or defined inside the class definition.

    The only required effect of this, is to disable the One Definition Rule — that is, to make it legal for the definition to be seen in multiple translation units without producing a linker error. Basically, it allows you to put the full definition in a header file

    Then there is the “inline” optimization, which consists of taking the function body, and inserting it instead of a function call.

    These meanings are almost entirely orthogonal. A function can be inlined by the compiler whether or not you, the programmer, marked it as inline. (Although it is harder and less common for a compiler to be able to inline if the function is called in a different translation unit than the one in which it was defined) A function marked inline in C++ may or may not be inlined by the compiler. The compiler tries to estimate the possible benefit of this, based on code size, how frequently the function is called, number of call sites and such heuristics. The result is that the compiler is pretty good at determining when the inlining optimization is worthwhile, and your best bet is usually to leave it to do its thing alone.

    You should simply mark functions as inline when 1) it is convenient for you, and 2) you want to ensure that the compiler has the option of applying the inlining optimization.

    But you’re not forcing the compiler to inline anything. You’re merely arranging the code so that it can, if it chooses to do so, inline the function call.

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

Sidebar

Related Questions

No related questions found

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.