why bug in the program

P

prava sahoo

class foo
{
static int xxx;
static int zzz;
};
static int xxx =2;
int foo::xxx = 1; // error here
int foo::zzz = 1;
static int zzz =2;

When compiled (gcc 2.4.5) It give an error for redefining xxx, but
not
for zzz,

because xxx is a static variable and its scope is inside the total
program so we can create only a single copy of this variable but zzz
in general variable inside class foo zzz is local to that class
foo .outside the class zzz is a variable of the program program .
these are consider two different variable with same name.
 
M

Miles Bader

prava sahoo said:
When compiled (gcc 2.4.5) It give an error for redefining xxx, but not
for zzz,

Do you really have gcc version 2.4.5?! It was released about 20 years
ago!!! :OOO

[Recent versions of gcc (4.4-4.7) don't give any error for your
example.]

-miles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top