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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:29:38+00:00 2026-06-11T02:29:38+00:00

I have done C# and C, but still, when I come to this C++

  • 0

I have done C# and C, but still, when I come to this C++ project, I am a little stucked for this little code style problem.

I have a couple of const variables(might be strings or numbers) in a C++ program, and I want to gather them in one place and access them from other classes.

For example, in C# and java, we can have a resource file or a config file to store all those data, or maybe just a singleton or static class.

But what is the best way I should do it with C++? should I put the const variables in a header file or make a class like JAVA?

  • 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-11T02:29:39+00:00Added an answer on June 11, 2026 at 2:29 am

    IMO this is one of the shortcoming of C# and Java – everything has to be inside a class.

    In C++ you have two three options:

    • inside a class
    • in a namespace
    • free variables (don’t)

    If your constants are logically related to a class, put them in the class. Otherwise, use a namespace.

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

Sidebar

Related Questions

Ok I am still learning this... I have Googled and done some research but
i have done some code in jquery but where i commented in this bellow
As I have done my research regarding this problem of mine, I still have
I have done this before but I forgot where in my app I have
i have done a code that will download the file from internet. but the
I'm very much still a beginner at programming but I have come across the
I Have done a site but want to redirect it to another subdomain in
I am new to LINQ to SQL, but have done a lot of database
I have done XML parsing before but never on a massive scale. If I'm
I have done a load of searching but haven't found anything. There seem to

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.