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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:20:25+00:00 2026-05-19T11:20:25+00:00

Possible Duplicate: When to use inline function and when not to use it ?

  • 0

Possible Duplicate:
When to use inline function and when not to use it ?

I have seen many source codes using different syntaxes regarding the inline directive.

namespace Foo
{
    class Bar
    {
        public:

            // 1 - inline on the declaration + implementation
            inline int sum1(int a, int b) { return a + b; }

            // 2 - inline on template declaration + implementation
            template <typename T>
            inline T sum2(T a, T b) { return a + b; }

            // 3 - Nothing special on the declaration...
            int sum3(int a, int b);
    };

    // 3 - But the inline directive goes after
    // In the same namespace and still in the header file
    inline int Bar::sum3(int a, int b) { return a + b; }
}

I failed to find an “official” guidelines regarding the usage of inline: I only know that inline is just a hint to the compiler and that it enforces internal linkage. I know not much about it.

Here are my questions:

  • Is (1) good practice ?
  • In (2), is the inline directive always needed ? (My guess would be “no”, but I can’t explain why). When is it needed ?
  • (3) seems to be the most used syntax. Is there anything wrong with it or should I use it too ?
  • Is there any other use (syntax) of inline I am unaware of ?
  • 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-19T11:20:26+00:00Added an answer on May 19, 2026 at 11:20 am

    No, and no! inline is not just a hint to the compiler and it doesn’t enforce internal linkage.

    inline is implicit on functions defined in a class body so you only need it on functions defined outside of classes. You should use it when, and only when, you need to enable the changes to the one definition rule that inline makes.

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

Sidebar

Related Questions

Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Escape string for use in Javascript regex I have a msg like
Possible Duplicate: When to use virtual destructors? let's say i have an abstract class
Possible Duplicate: When do you use the “this” keyword? If I have the following
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the
Possible Duplicate: When to use “strictfp” keyword in java? What is the use of
Possible Duplicate: Internationalization in SSRS We use SQL Server Reporting Services for our web
Possible Duplicate: How can I use a carriage return in a HTML tooltip? I'd
Possible Duplicate: When should you use 'friend' in C++? I was brushing up on
Possible Duplicate: Parameterizing a SQL IN clause? Hi, I have a query looks like

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.