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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:49:01+00:00 2026-05-15T07:49:01+00:00

While I was reading the accepted answer of this question , I had the

  • 0

While I was reading the accepted answer of this question, I had the following question:

Typically, methods are defined in header files (.hpp or whatever), and implementation in source files (.cpp or whatever).

One of the main reasons it is bad practice to ever include a “source file” (#include <source_file.cpp>) is that its methods implementation would then be duplicated, resulting in linking errors.

When one writes:

#ifndef BRITNEYSPEARS_HPP
#define BRITNEYSPEARS_HPP

class BritneySpears
{
  public:

    BritneySpears() {}; // Here the constructor has implementation.
};

#endif /* BRITNEYSPEARS_HPP */

He is giving the implementation of the constructor (here an “empty” implementation, but still).

But why then including this header file multiple times (aka. on different source files) will not generate a “duplicate definition” error at link time ?

  • 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-15T07:49:03+00:00Added an answer on May 15, 2026 at 7:49 am

    Inline functions are exceptions to the “one definition rule”: you are allowed to have identical implementations of them in more than one compilation unit. Functions are inline if they are declared inline or implemented inside a class definition.

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

Sidebar

Related Questions

While reading this class BitmapFactory I noticed that almost all methods inside are static.
While reading the answers to this question I got a doubt regarding the default
While reading this , I'm confused by the following examples: // Example 2: Explicit
While reading through another question here, on creating a URL shortening service, it was
While reading proggit today, I came upon this comment in a post about how
While reading some question on a site I came across below question where a
While reading this article, I got a doubt. I understood that while trasferring small
While reading Jack Shirazi's 'Java performance tuning', I came across the following statement: Instance
While reading this SO post - Is there a version of JavaScript's String.indexOf() that
While reading Bruce Eckel i came across the following example: #include <cstdio> #include <cstdlib>

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.