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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:26:53+00:00 2026-05-27T12:26:53+00:00

I had this header file that contain a lot of inline functions,after compile it

  • 0

I had this header file that contain a lot of inline functions,after compile it says:
multiple definition of function***,the function which looks like this:

inline int testab(int a, int b)
{
        return a>b;
}

after I add static in front of inline, the error is gone. Is it the right way to do it? Or am I missing something? I thought I could set up inline functions in a header like that.

  • 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-27T12:26:53+00:00Added an answer on May 27, 2026 at 12:26 pm

    inline or not, once the header gets copied in at least two files, you cannot link the files anymore.

    The only way you can safely implement a function in a header is to use static. This way, each copy of the function would be invisible to the other ones.

    Note that there is no restriction to using them together, so you can safely write:

    static inline bool testab(int a, int b)
    {
            return a>b;
    }
    

    Edit: More details

    inline tells the compiler that you think the function is small enough to be inlined. That is you tell the compiler that you don’t think the extra space for inlining the function matters much as opposed to the (slight) (possible) performance gain for it. Most compilers however are intelligent enough to decide that on their own and with your keyword, they would just tend a bit more to inline, and not necessarily always listen to you. This depends on the compiler, of course. Some compilers may completely ignore the keyword.

    static on the other hand, means that whatever scope a static variable is defined, it will be invisible outside it. If you have a static variable in a function, it would be invisible outside it. If you have a static variable in a file (that is, a static global variable), it will be invisible outside it, which means the symbol is not there after compiling for the linker to see and get confused. That is why, if you have written a library in which there are global variables or functions that are not supposed to be visible outside the library, you should declare them as static.

    Edit 2: Correction

    Apparently, according to this answer, inline functions should not have its identifiers exported for the linker. Nonetheless, one can attach static to it either way just to make it more clear. Also apparently, some compilers export the identifier anyway, so in those cases static is indeed necessary.

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

Sidebar

Related Questions

I had this nasty bug that disappeared in the past but now after quite
I'm trying to parse a file that looks like this: || Column Header A
I had this doubt for sometime now, some people say that there's no such
I had this error when I browse new web site that site sub from
I had never had this error before, and I didn't move any file, or
I'm getting a compiler error with this header file: #ifndef GAME1_H #define GAME1_H #include
I am looking for a good tool or library that takes a C/Cpp/header file
Basically I have code which looks like this inside a header file: class Bar;
I had written C++ code for a problem. After that i have tried to
Is it possible to make a C++ header file (.h) that declares a class,

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.