why bug in the program

Discussion in 'C++' started by prava sahoo, Feb 1, 2012.

  1. prava sahoo

    prava sahoo Guest

    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.
     
    prava sahoo, Feb 1, 2012
    #1
    1. Advertising

  2. prava sahoo

    Miles Bader Guest

    prava sahoo <> writes:
    > 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

    --
    Clarionet, n. An instrument of torture operated by a person with cotton in his
    ears. There are two instruments that are worse than a clarionet -- two
    clarionets.
     
    Miles Bader, Feb 1, 2012
    #2
    1. Advertising

  3. prava sahoo

    gwowen Guest

    On Feb 1, 7:11 am, Gareth Owen <> wrote:

    > foo::xxx = 1; // the compiler already knows it's an int.


    Sorry, brain malfunction. Please please please ignore that.
     
    gwowen, Feb 1, 2012
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Why, why, why???

    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    572
    Juan T. Llibre
    Jan 27, 2005
  2. Mark
    Replies:
    20
    Views:
    1,648
    Dave O'Hearn
    Dec 27, 2004
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    901
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,961
    Smokey Grindel
    Dec 2, 2006
  5. Trollen Lord
    Replies:
    50
    Views:
    452
    Jari Williamsson
    Nov 29, 2007
Loading...

Share This Page