Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > class name hiding - why?

Reply
Thread Tools

class name hiding - why?

 
 
Ole Nielsby
Guest
Posts: n/a
 
      09-08-2007
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?


 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      09-08-2007
* 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
 
Reply With Quote
 
 
 
 
Ole Nielsby
Guest
Posts: n/a
 
      09-08-2007
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Script for Hiding/Un-Hiding Text On Click Ste Javascript 41 08-01-2007 02:35 PM
Hiding the public members of a class without modifying the CLASS Brahmam ASP .Net 3 01-11-2006 12:00 AM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57