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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:55:33+00:00 2026-05-15T09:55:33+00:00

Is it preferred to define inline methods like: // math.h class Math { public:

  • 0

Is it preferred to define inline methods like:

// math.h
class Math
{
public:
    inline static int sum(int a, int b)
    {
        return a + b;
    }
};

or

// math.h
class Math
{
public:
    static int sum(int a, int b);
};

// math.cpp
inline int Math::sum(int a, int b);
{
    return a + b;
}

and why? Is there any difference? Should you leave inlining entirely up to the compiler? (I know this is pretty subjective but I’d like to hear some opinions and reasons)

Also, I believe it is true that most compilers will inline or not inline of their own accord regardless of the presence or absence of the inline keyword?

  • 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-15T09:55:33+00:00Added an answer on May 15, 2026 at 9:55 am

    Inlining is entirely up to the compiler. The inline keyword, like the old C register keyword is a suggestion to the compiler to do some optimisation.

    However, compiler writers know so much more than we lesser beings about their target architectures that this is really unnecessary.

    Because of that, I don’t ever use inline so the question is moot (for me) but I would prefer to keep all code out of headers since that always led to double-defined symbols in C compilers.

    Putting code in header files also leaks information unnecessarily. People using your headers should not be able to see the implementation details.

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

Sidebar

Related Questions

Is there any restriction on using #define'd functions/inline functions inside Assembly files. I referred
In embedded programming, for example, #define GLOBAL_CONSTANT 42 is preferred to const int GLOBAL_CONSTANT
What is your preferred approach to serializing BigDecimal in GWT? Are there any clever
I need to define a class like this: class Color { private: union Data
What is the preferred way to work with Singleton class in multithreaded environment? Suppose
Is there a preferred algorithm for converting a 2-digit year into a 4-digit year?
Which is the preferred way of defining class properties in Python and why? Is
To define a map from int to struct vertex, should I define map[int]vertex or
From what I understand, #define x y and const int x = y; should
I can define a class with a property to access my ivars from outside

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.