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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:40:26+00:00 2026-05-10T21:40:26+00:00

All the member variables and member functions in my class ClassA are static. If

  • 0

All the member variables and member functions in my class ClassA are static.

If a user is trying (by mistake) to create an object of this class, he receives a warning: ‘ClassA, local variable never referenced’, because all the functions are static, so this object is never referenced. So, I want to prevent the user from trying to create an object of this class.

Would it be enough to create a private default (no variables) constructor? Or do I have to also create private copy constructor and private assignment operator (to prevent using the default constructors)? And if I do have to create them too, maybe it would be better just to create some dummy pure virtual function instead, and this will prevent the user from creating an object?

Thank you

  • 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. 2026-05-10T21:40:26+00:00Added an answer on May 10, 2026 at 9:40 pm

    Like others said, a namespace is what you should use. If you want to stay with your class, create a class that has a private constructor, and derive from it, to make your intention obvious:

    class NonConstructible {      NonConstructible(); };  class SuperUtils: NonConstructible {     static void foo();     // ...     static std::vector<int> globalIDs;     // ... }; 

    Ok, now let’s look into the namespace which are the one and only way to do this:

    namespace SuperUtils {     void foo() {         // ....     }      std::vector<int> globalIDs; }; 

    You can call that using SuperUtils::foo(); in both cases, but the namespace has the advantage that in a scope you can use the namespace declaration and directive to bring certain or all members into the current scope, so that you can reference them without using SuperUtils:::

    void superFunction() {     using namespace SuperUtils;     foo(); } 

    While generally that should be avoided, it can be helpful when the method is using exclusively much stuff from SuperUtils, which then can improve the readability of the code.

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

Sidebar

Related Questions

To specialize a class template, one has to redefine all of the member functions
I understand that one benefit of having static member functions is not having to
I'm wondering how static member variables are typically implemented in languages like C++ and
One of my WCF functions returns an object that has a member variable of
I am a member of all the roles (Browser, Content Manager, My Reports, Publisher,
I would like to override the default behavior of the offsetParent member of all
I've been trying to get this code to work for what feels like an
All members are camel case, right? Why True/False but not true/false, which is more
Is it possible to generate a list of all source members within an iSeries
I need to generate a new interface at run-time with all the same 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.