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

  • Home
  • SEARCH
  • 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 4340290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:19:45+00:00 2026-05-21T11:19:45+00:00

Coming from a Java background it is new for me to deal with the

  • 0

Coming from a Java background it is new for me to deal with the choice of creating a class or just implementing the functions I might need. Normally this is no question when it comes to modeling something which could have a state.

Now I am implementing a shared library which has no main function and exclusively static member functions. Does something speak against creating a class to encapsulate the functions?

Further I wanted to encapsulate further code, especially auxillary functions, in another file. The execute code is always the same and the state of it does not change, so I guess I would declare them also static – so the same questions arises here to.

  • 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-21T11:19:46+00:00Added an answer on May 21, 2026 at 11:19 am

    Not sure if I completely understand you but yes you can create a container class that provides static methods. It may be worthwhile to make the constructors private to prevent people from instantiation an instance of the class.

    class HelperFunctions
    {
    public:
        static void DoSomethingUseful() { /* useful bits */ }
        // yata yata
    private:
        HelperFunctions(); // private default constructor
        HelperFunctions(const HelperFunctions&); // private copy constructor
    };
    

    Then you could do something like this:

    HelperFunctions::DoSomethingUseful();
    

    But you couldn’t do something like this:

    HelperFunctions myHelperFunction; // private constructor = compile error
    

    You also could create namespaces for the purpose of organization non-member functions.

    namespace HelperFunctions
    {
       void DoSomethingUseful() { /* useful bits */ }
       // yata yata
    }
    

    Remember you can define namespaces across multiple files as well making these particular useful for grouping objects and functions wherever they may be. This is preferable as it logically separates the functions making the design and intended use more obvious

    Unlike Java where everything is a method in C++ we can have functions at a global, namespace, or member scope. You also can have non-member friend functions which can access internal members of a class without being a member of the class themselves.

    Basically you can do whatever you want including shoot yourself in the foot.

    Edit: Why so serious?

    I wasn’t suggesting what the OP should or shouldn’t do. It seemed as though they were new to C++ coming from the Java world where everything is a method and all “functions” are class members. To that affect my answer was to show how firstly you can create something in C++ similar to what you might have in Java and secondly how you can do other things as well and why that is.

    As others have stated it’s considered good practice to prefer non-member non-friend functions when possible for various reasons. I agree if you do not need an object with state than you probably shouldn’t design one. However I’m not sure if the OP was looking for a philosophical discussion on best practice in design and implementation or just a curiosity for equivalent C++.

    I had hoped my last line joking about shooting yourself in the foot was enough to make the point that “just because you can, doesn’t mean you should” but perhaps not with this crowd.

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

Sidebar

Related Questions

I'm very new to Python (I'm coming from a JAVA background) and I'm wondering
I am new to C# and .Net and am coming from a Java background.
Coming from a java background, one of the things I am used to is
When I was learning Java coming from a background of some 20 years of
I'm a relatively new Java programmer coming from C++/STL, and am looking for a
Coming from a corporate IT environment, the standard was always creating a class library
Coming from Java background I am guessing this is expected. I would really love
Coming from a Java background, I'm used to the common practice of dealing with
Coming from a Java background, this is the way I'm thinking: The server provides
Coming from a Java background, this is the way I'm thinking: The server provides

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.