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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:43:47+00:00 2026-05-19T23:43:47+00:00

Possible Duplicates: Where would you use a friend function vs a static function? C++:

  • 0

Possible Duplicates:
Where would you use a friend function vs a static function?
C++: static member functions

When is it appropriate to use a static member function in C++? Please give me a real world example.

  • 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-19T23:43:48+00:00Added an answer on May 19, 2026 at 11:43 pm

    Good uses of static member functions:

    • Meta-programming. Real-world example is template std::char_traits. All member functions are static
    • Making it a static member function gives it access to private members of the class, although a friend would suffice here too
    • A protected static member function thus is accessible only to the class and classes derived from it.

    Note that the last case applies to a protected static member function but not a private one. In the latter case you would just put it into the compilation unit of the class, hiding it away as an implementation detail. For a protected one though you want it to be visible, albeit in a restricted way.

    A typical case of that one is “cheating” the lack of inheritance of friendship.

    class B
    {
       friend class A;
       // lots of private stuff
    };
    
    class A
    {
    protected:
       static void callsSomePrivateMembers( B& b );
    };
    
    class AChild : public A
    {
       void foo( B& b );
    }
    
    void AChild::foo( B& b )
    {
          // AChild does not have private access to B as friendship is not inherited
          // but I do have access to protected members of A including the static ones
    
        callsSomePrivateMembers( b ); // get to call them through a back-door
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: Why use pointers? Passing a modifiable parameter to c++ function Why would
Possible Duplicate: When should you use 'friend' in C++? I was brushing up on
Possible Duplicates: Why would a sql query have “where 1 = 1” Why would
Possible Duplicates: Are PHP short tags acceptable to use? What does “<?=” mean when
Possible Duplicates: Valid use of goto for error management in C? Examples of good
Possible Duplicates: Should I use public properties and private fields or public fields for
Possible Duplicates: How would you set a variable to the largest number possible in
Possible Duplicates: Is “for(;;)” faster than “while (TRUE)”? If not, why do people use
Possible Duplicate: When or why would you use a right outer join instead of
Possible Duplicate: Complex CSS selector for parent of active child How would I make

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.