objects

is the global data member shared among the various objects of the same class?(this is true in case of static variables)

Can you post an example? I'm not sure I understand what you mean.
in the following code..i think that the count variable is shared between the objects
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream.h> 
int count=0; 
class obj 
{ 
public : 
 obj(){count++;} 
 ~obj(){count--;} 
}; 
int main() 
{ 
 obj A,B,C,D,E; 
 obj F; 
 { 
 obj G; 
 } 
 cout<<count; 
 return 0; 
} 
count is not a member of any classes but just a global variable. So it can be accessed and modified by any object. As they all access same variable, any changes made by one of them would be visible to others

Also I notice that you have a very outdated compiler. <iostream.h> was made illegal in previous century. I suggest you to update it ASAP.
Last edited on
thnku :)
Topic archived. No new replies allowed.