C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-07-2008, 07:57 AM   #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
e66n06 is offline   Reply With Quote
Old 01-07-2008, 08:27 AM   #2
Code Goddess
 
Prelude's Avatar
 
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   Reply With Quote
Old 01-07-2008, 12:58 PM   #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   Reply With Quote
Old 01-07-2008, 01:17 PM   #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   Reply With Quote
Old 01-07-2008, 02:29 PM   #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   Reply With Quote
Old 01-07-2008, 02:41 PM   #6
Mysterious C++ User
 
Elysia's Avatar
 
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:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 10:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22