class name hiding - why?

O

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? What's the point of having a class/enum and a function with
the same name? Any examples of practical use?
 
A

Alf P. Steinbach

* 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
 
O

Ole Nielsby

Alf P. Steinbach said:
* 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.
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top