class name hiding - why?

Discussion in 'C++' started by Ole Nielsby, Sep 8, 2007.

  1. Ole Nielsby

    Ole Nielsby Guest

    The standard (last prelim ed.) says:

    ---quote---
    3.3.7 - Name hiding [basic.scope.hiding]

    -2- A class name (class.name) or enumeration name (dcl.enum) can
    be hidden by the name of an object, function, or enumerator declared
    in the same scope. If a class or enumeration name and an object,
    function, or enumerator are declared in the same scope (in any order)
    with the same name, the class or enumeration name is hidden wherever
    the object, function, or enumerator name is visible.
    ---quote---

    Why is this? What's the point of having a class/enum and a function with
    the same name? Any examples of practical use?
     
    Ole Nielsby, Sep 8, 2007
    #1
    1. Advertising

  2. * Ole Nielsby:
    > The standard (last prelim ed.) says:
    >
    > ---quote---
    > 3.3.7 - Name hiding [basic.scope.hiding]
    >
    > -2- A class name (class.name) or enumeration name (dcl.enum) can
    > be hidden by the name of an object, function, or enumerator declared
    > in the same scope. If a class or enumeration name and an object,
    > function, or enumerator are declared in the same scope (in any order)
    > with the same name, the class or enumeration name is hidden wherever
    > the object, function, or enumerator name is visible.
    > ---quote---
    >
    > Why is this?


    Presumably you can still refer to the class, say, X, by writing "class
    X" or "struct X". Don't know about the enum. If would be more
    difficult if the class name hid the function, object or enumerator name.


    > What's the point of having a class/enum and a function with
    > the same name?


    Presumably because old C placed names in different "namespaces", like
    struct names in struct namespace where you had to write "struct X",
    unless you used a typedef, so, sort of backwards compatibility with C.


    > Any examples of practical use?


    None that I can think of.


    Cheers, & hth.,

    - Alf
     
    Alf P. Steinbach, Sep 8, 2007
    #2
    1. Advertising

  3. Ole Nielsby

    Ole Nielsby Guest

    Alf P. Steinbach <> wrote:

    >* Ole Nielsby:
    >> What's the point of having a class/enum and a function with
    >> the same name?

    >
    > Presumably because old C placed names in different "namespaces" [...]
    >> Any examples of practical use?

    >
    > None that I can think of.
    >
    > Cheers, & hth.,


    It does help. So, it's just a compatibility quirk I don't have to worry
    about.
    Thx/Ole N.
     
    Ole Nielsby, Sep 8, 2007
    #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. Brahmam
    Replies:
    3
    Views:
    560
    Francois Beaussier
    Jan 11, 2006
  2. corejavagroups
    Replies:
    6
    Views:
    3,570
    Roedy Green
    Nov 21, 2005
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    902
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,964
    Smokey Grindel
    Dec 2, 2006
  5. Ste
    Replies:
    41
    Views:
    810
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
Loading...

Share This Page