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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:59:12+00:00 2026-06-05T03:59:12+00:00

I began to write my program in a single cpp-file but now I have

  • 0

I began to write my program in a single cpp-file but now I have too much code so I decided to separate it. But the problem is that I have many constants, includes and some other things that I want to have all in one place. Unfortunately, all of them are needed by dependent parts of code so I can’t do it with usual include files.

What would help me?

(I write under Linux and compile with command-line)

(Sorry for my English :))

  • 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-06-05T03:59:15+00:00Added an answer on June 5, 2026 at 3:59 am

    As Hristo said, you should generally write the definitions in header files and write the implementation in the source code files.

    To answer your question however:

    But the problem is that I have many constants, includes and some other things that I want to have all in one place.

    What I’ve typically done is create a single file called something like “common.h” or “defs.h” (I took the idea from Doom…) and that file has many defines that you find you need throughout your entire program. If you are using constants, declare the constants in the header file like so:

        extern const int MAX_SOMETHING;
        extern const bool TRUTH_VALUE;
    

    and make a complementary source file (defs.cpp or common.cpp) that defines these constants:

        const int MAX_SOMETHING = 5;
        const bool TRUTH_VALUE = true;
    

    so now when you include the common/defs.h in other source files, the extern keyword will tell that source file that the definition is in another source file (its in the common/defs.cpp) so it will find the definition in there, and you can use it anywhere where you have included common/defs.cpp.

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

Sidebar

Related Questions

I am trying to write a program in C language(code::blocks in windows). I have
I began reading the book Code Complete 2nd edition, but stopped reading when I
I began writing an app using declarative_authorization ( http://github.com/stffn/declarative_authorization ) but I'm now wondering
I have problems in a following code: program Project4; {$APPTYPE CONSOLE} uses SysUtils, RTTI;
I have to write a program that performs highly computationally intensive calculations. The program
I have a question. I want to write a chess like program applying the
I have some problems with Eclipse: Sometimes I write the code and compile it
I have to write program that counts how many different letters are in string.
I have run my program and everything works great. I am now trying to
I've been trying to write an iterative dir in c. I began with a

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.