Thread: question about static members and functions

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    54

    question about static members and functions

    I have a class called cEntity which has some static variables and some static methods

    I then create a new class from cEntity.. cPlayer: public cEntity

    I was hoping that someone could tell me what happens to the static varible and methods when inheritance is used.

    Are the static variables and methods accessable to the derived class or not?

    I'm a bit confused XD

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Are the static variables and methods accessable to the derived class or not?
    It depends on the accessibility of the variables and methods. If they're private, no. If they're public or protected, why wouldn't they be?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    21
    I think that you can access to static variables and methodos even if they are private. no sure but you can access do none static private variables so i think you can access to static private variables, but like i said not sure

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I think that you can access to static variables and methodos even if they are private.
    No, you can't. Prelude is right. You can only access public and protected members from the derived class. Whether they are static or not has no effect on accessibility.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    21
    You are right.
    But if mother class is friend of derived class i think you can access private variable and methods but i'm not sure again.. Right?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes. If it's a friend declared class, then it can access private members and functions and otherwise not; use with caution.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking error with static template class members
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 04-02-2009, 12:31 PM
  2. initializing static members
    By steve1_rm in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2008, 05:45 AM
  3. Replies: 10
    Last Post: 07-26-2008, 08:44 AM
  4. Using private class members in static functions
    By sethjackson in forum C++ Programming
    Replies: 2
    Last Post: 09-23-2005, 09:54 AM
  5. Private Static class members
    By earth_angel in forum C++ Programming
    Replies: 13
    Last Post: 08-29-2005, 06:37 AM