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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:14:41+00:00 2026-05-28T03:14:41+00:00

Consider: // In Vector2.h class Vector2 { public: // returns the degrees in radians

  • 0

Consider:

// In Vector2.h

class Vector2
{
    public:
        // returns the degrees in radians
        static double calcDir(double x, double y);
}

// In Vector2.cpp

double Vector2::calcDir(double x, double y)
{
    double rad = ...;
    return rad;
}

Why isn’t the keyword static required in the signature in Vector2.cpp? When I try this, it produces an error:

static double Vector2::calcDir(double x, double y)

It seems inconsistent to me. All other parts of the method signature are required to be repeated in the .cpp file (return type, method name (duh), names and types of args, const-ness). I don’t like not knowing at a glance whether a method is static or not (when looking at the implementation).

Is there a reason this is not only not required, but forbidden?

  • 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-28T03:14:42+00:00Added an answer on May 28, 2026 at 3:14 am

    It’s because static has a special meaning when used in a class definition. In a class definition it identifies the function as a static member function which means it doesn’t operate on a class instance but can be called independently.

    Outside of a class static gives a function internal linkage but this is illegal on (even static) member functions because class members must have the same linkage as the class of which they are a member (almost always external, and certainly external in cases where you can defined member functions outside of the class definition).

    From a language point of view, the declaration of members inside a class definition follows one set of language rules where static has its special class meaning. Outside of a class definition, all function definitions – members and non-members – follow the same set of rules where static has it’s other meaning which is not valid for members of classes with external linkage.

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

Sidebar

Related Questions

Consider the following example code: class Foo { }; class Bar : public Foo
Consider the following code : #include <vector> #include <iostream> class a { public: int
Consider these classes. class Base { ... }; class Derived : public Base {
Consider the following: class A { public: const int c; // must not be
Please consider this class: class A { public: //public in this example string a1;
Consider the following class. class mapping_items { public: mapping_items(){} void add(const mapping_item* item) {
Consider this program: #include <map> #include <vector> typedef std::vector<int> IntVector; typedef std::map<IntVector,double> Map; void
Consider the following public method that adds an integer variable to a vector of
Consider the following piece of code: class B { private: // some data members
Consider the below C++ code class B; class A{ private: B* mB; }; class

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.