![]() |
| | #1 |
| Registered User Join Date: Jan 2007
Posts: 54
| question about static members and functions 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 |
| e66n06 is offline | |
| | #2 |
| Code Goddess Join Date: Sep 2001
Posts: 9,664
| >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. |
| Prelude is offline | |
| | #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 |
| skiler is offline | |
| | #4 |
| Registered User Join Date: Jan 2005
Posts: 7,252
| >> 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. |
| Daved is offline | |
| | #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? |
| skiler is offline | |
| | #6 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,783
| Yes. If it's a friend declared class, then it can access private members and functions and otherwise not; use with caution.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Linking error with static template class members | cunnus88 | C++ Programming | 6 | 04-02-2009 12:31 PM |
| initializing static members | steve1_rm | C++ Programming | 1 | 11-29-2008 05:45 AM |
| free functions (or static members) to access private function from different class | csonx_p | C++ Programming | 10 | 07-26-2008 08:44 AM |
| Using private class members in static functions | sethjackson | C++ Programming | 2 | 09-23-2005 09:54 AM |
| Private Static class members | earth_angel | C++ Programming | 13 | 08-29-2005 06:37 AM |