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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:36:18+00:00 2026-06-14T17:36:18+00:00

Here’s a minimal working example: A.h: class A{ static int a_member_function(); }; A.cpp #include

  • 0

Here’s a minimal working example:

A.h:

class A{
        static int a_member_function();
};

A.cpp

#include "A.h"
int A::a_member_function(){return 5;}


int main(){ return 1;}

This code compiles and runs, but, it seems to me that:

static int A::a_member_function(){return 5;}

could just as easily be used to define the static member function of class A. Indeed, it seems like it could actually be rather useful to have this requirement, since it would remind the reader of the .cpp file that a_member_function is static.

However, this clearly doesn’t work:

error: cannot declare member function ‘static int A::a_member_function()’ to have static linkage [-fpermissive]

So why doesn’t it work? What’s the reasoning behind this decision?

  • 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-14T17:36:19+00:00Added an answer on June 14, 2026 at 5:36 pm

    The reason behind is C++ spirit to try and minimize the number of its keywords and keep backward compatibility with C: static in that position has an entirely different meaning.

    It all predates back to C. “static” functions in C are functions that are unique to a compilation unit (a .c file). They can’t be accessed by other compilation units (it’s one way to have encapsulation in C). This usage is still valid in C++. You can also do the same for global variables to limit their scope.

    Though, in C++ you also want to declare member functions as static for a different reason: those functions belong to class but do not require and instance of said class to run (I bet you know that already, I am just trying to be complete).

    Defining a member function as static would lead to a contradiction: that function must be accessed outside of its translation unit.

    There’s another case of keyword reuse between C and C++, the auto keyword in C++11, but it is less likely to be a problem.

    Note:
    The same thing happens with the virtual keyword which is present in the declaration and not the definition.

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

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here is a code snippet I was working with: int *a; int p =
Here is an example: I write html code inside of textarea, then I swap
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here's my code: // Not all headers are relevant to the code snippet. #include
here is my code, SiteMember class @OneToMany(mappedBy = member,cascade=CascadeType.ALL) private List<MemberThread> memberThread = new
Here's my class: public class JsoupParser { ArrayList<CompanyInfo> arr = new ArrayList<CompanyInfo>(); public static
Here is my code: i used set() and it return [3, 14, 6] items
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }

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.