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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:50:35+00:00 2026-05-26T03:50:35+00:00

Does the normal functions (and not the static ones) have only one copy for

  • 0

Does the normal functions (and not the static ones) have only one copy for a class in C++, meaning that all the objects refer to the same copy. If so what is the difference between normal function and static function. Also, my teacher was saying that we cannot call static functions of a class using “(object_name).(func_name)” notation but have to call it using the “class_name::(func_name)”, while I understand that this is the logical thing to do, but as far as the language is concerned, am I not allowed to call a static function using (object_name).(func_name) notation? Finally, cannot I initialize the static data members of a class in the constructor of the class or inside any other function of that class, but have to do so from outside the class?

  • 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-26T03:50:36+00:00Added an answer on May 26, 2026 at 3:50 am

    If by only one copy you mean all functions have the same location in memory, then yes, you are right. The difference is that static functions don’t require an object to be instantiated in order to be called. This also implies that you can’t access other non-static members of the class.

    As for the initialization, you can’t do it in the constructor since calling a static function that would access a static member would need the constructor to be called beforehand. There’s no way to guarantee that. You can change the static inside the constructor, but it must be initialized elsewhere.

    Think about this scenario:

    class A
    {
    static int x;
    public:
       A()
       {
          x = 3;
       }
       static int getX()
       {
          return x;
       }
    }
    
    int main()
    {
       A::getX(); //what would x be here? It hasn't been initialized since A() was not called.
    }
    

    As for calling the function with (object).(function) instead of (class)::(function), I believed you are allowed to do it, but why would you?

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

Sidebar

Related Questions

I have a medium-complex Rails app. The main controller (the one that does what
I have noticed that some of my ajax-heavy sites (ones I visit, not ones
Does anyone know why .hide(normal) does not seem to be working in jQuery 1.4.2?
The organization policy does not allow normal users be assigned to Administrators group of
Does a standard or normal diff format exist in SVN or only the unified
Generating normal columnar data in excel file is quite easy but does any one
Using an Oracle temporary table does not generate much redo log as a normal
I know that the normal member function of a template class will be instantiated
I have this php code that should take all the php files in a
I have a normal class called BaseView with a virtual method DisplayView . This

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.