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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:23:44+00:00 2026-05-13T09:23:44+00:00

I have found some threads that explain why C++ separates .cpp and .h files

  • 0

I have found some threads that explain why C++ separates .cpp and .h files (e.g. here). I’d be interested to know if it causes any problem if I don’t separate them. I don’t want to share the object files, so what’s the benefit of the separation on a small project? If it just slows down the compilation time, it’s not a big deal in my opinion. I want to re-implement a Java program in C++, so to me it seems much easier to keep a class in one file only. Example:

// Hello.cpp
#ifndef HELLO_20091218
#define HELLO_20091218

#include <iostream>
#include "Utils.cpp"

class Hello
{
public:
    void start()
    {
        std::cout << Utils::nrand(100) << "\n";
        // Utils and all other classes are written in a similar way
    }
};

#endif

There is a thing that troubles me. “Defining a member function inside the class asks the implementation to expand calls to it inline.” So if I do like this, everything is marked inline implicitly. Will it cause a larger executable or any other disadvantages?

  • 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-13T09:23:44+00:00Added an answer on May 13, 2026 at 9:23 am

    In C and C++ the smallest unit of compilation is the file. If you just don’t use header files and include everything in your “main” file, everytime you change something your whole program would have to be recompilled. For larger applications this can be a very good argument for separation of header and implementation. Also if another part of your application would live in another binary executable and you wan’t to reuse classes you are safe with header files while you will get alot of overhead without them.

    If you don’t care about those things (You’ll regret that.) there is no need in separate header files for you.

    About the inlining: The compiler will inline a lot of functions (sometimes even whole classes, so to speak) anyway, even if you don’t ask it to do that. Inlining is generally a benefit for performance. There are corner cases (large size of the executable can resolut in slower execution) but those are fairly unusual.

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

Sidebar

Ask A Question

Stats

  • Questions 291k
  • Answers 291k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think what you want is a DialogBox. This class… May 13, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer I think a pure SQL solution would invlolve using a… May 13, 2026 at 5:56 pm
  • Editorial Team
    Editorial Team added an answer You never specified SQL Server version, but for 2008 there… May 13, 2026 at 5:56 pm

Related Questions

I have a bit of code, which I can't figure out properly. The problem
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Recently, I found myself having to write up some concerns I have about race
I have a website that i've been working on for about a year now.
I'm developing an ASP.Net web application which makes use of MySQL via the MySQL-Provided

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.