Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: C++ reluctant to overload function

Reply
Thread Tools

Re: C++ reluctant to overload function

 
 
James Kanze
Guest
Posts: n/a
 
      10-13-2010
On Oct 13, 6:21 pm, Juha Nieminen <(E-Mail Removed)> wrote:
> Victor Bazarov <(E-Mail Removed)> wrote:
> > On 10/12/2010 12:37 PM, Juha Nieminen wrote:
> >> Victor Bazarov<(E-Mail Removed)> wrote:
> >>> Name lookup when in a member function finds
> >>> the member 'foo' which actually *hides* any other 'foo', and that's why
> >>> the '<unnamed namespace>::foo' should NOT be found during that lookup
> >>> and is *not* considered an overload.


> >> What is the rationale for that? I can't immediately think
> >> of a reason or notivation for that.


> > Rationale for what, exactly? For the rules of hiding?
> > Names defined in a closer scope hide names defined in the
> > outer scope. It's an old rule, that AFAICT existed from the
> > start in C++. For example,


> foo(int) is not the same thing as foo(int,int). They are two different
> functions with different signatures. In the original post one is hiding
> the other. I can't understand the rationale for that.


And double foo is not the same thing as int foo. Never the
less, a declaration of double foo in an inner scope will hide
a declaration of an int foo in an outer.

It's purely an issue of name lookup. Once the compiler has
found the name(s), it can decide whether the multiple
declarations are legal or not. But any presence of a name in
a nested scope hides all occurances of that name in outer
scopes. (In the case of function calls, some additional names
may be brought in by ADL. And templates obey somewhat special
rules as well.)

This is the rule in all languages with block scope that I know.
It would be very confusing if, in C++, functions (and only
functions) violated this rule---for that matter, I find the
results of ADL confusing, largely because they do violate this
rule.

--
James Kanze
 
Reply With Quote
 
 
 
 
Steve Pope
Guest
Posts: n/a
 
      10-13-2010
Niklas Holsti <(E-Mail Removed)> wrote:

>In Ada, if an inner scope defines a function
>or procedure with the same name as a function or procedure in an outer
>scope, the inner name hides the outer only if the parameter profiles
>match, otherwise the inner overloads the outer.


Thanks.

I am curious then if Ada generally facilitated separate compilation, and
subsequent linking, of modules, in a C/C++ manner.

Steve
 
Reply With Quote
 
 
 
 
Niklas Holsti
Guest
Posts: n/a
 
      10-13-2010
Steve Pope wrote:
> Niklas Holsti <(E-Mail Removed)> wrote:
>
>> In Ada, if an inner scope defines a function
>> or procedure with the same name as a function or procedure in an outer
>> scope, the inner name hides the outer only if the parameter profiles
>> match, otherwise the inner overloads the outer.

>
> Thanks.
>
> I am curious then if Ada generally facilitated separate compilation, and
> subsequent linking, of modules, in a C/C++ manner.


Yes, certainly. An Ada program is usually divided into several modules,
or compilation units. A compilation unit is usually a "package", which
is a bit like a C++ namespace, but it can also be a single procedure or
function.

Each module is usually represented by two source files: a specification
file, analogous to a C/C++ header file, and a body (implementation)
file. Both specification files and body files are compiled separately.

The compilation-unit structure is a core part of the Ada syntax, not a
preprocessor feature like #include. Consequently most Ada compilers have
a simple "build" command to (re)build the program's executable by
compiling and linking whatever compilation units are needed. Makefiles
are usually unnecessary.

(Apologies for advertising Ada on a C++ forum, but the question was
asked

--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
 
Reply With Quote
 
Steve Pope
Guest
Posts: n/a
 
      10-13-2010
Niklas Holsti <(E-Mail Removed)> wrote:

>Steve Pope wrote:


>> Niklas Holsti <(E-Mail Removed)> wrote:


>>> In Ada, if an inner scope defines a function
>>> or procedure with the same name as a function or procedure in an outer
>>> scope, the inner name hides the outer only if the parameter profiles
>>> match, otherwise the inner overloads the outer.

>>
>> Thanks.
>>
>> I am curious then if Ada generally facilitated separate compilation, and
>> subsequent linking, of modules, in a C/C++ manner.

>
>Yes, certainly. An Ada program is usually divided into several modules,
>or compilation units. A compilation unit is usually a "package", which
>is a bit like a C++ namespace, but it can also be a single procedure or
>function.
>
>Each module is usually represented by two source files: a specification
>file, analogous to a C/C++ header file, and a body (implementation)
>file. Both specification files and body files are compiled separately.
>
>The compilation-unit structure is a core part of the Ada syntax, not a
>preprocessor feature like #include. Consequently most Ada compilers have
>a simple "build" command to (re)build the program's executable by
>compiling and linking whatever compilation units are needed. Makefiles
>are usually unnecessary.


>(Apologies for advertising Ada on a C++ forum, but the question was
>asked


Thanks. I have not really looked at Ada for 30 years. (Literally,
I studied it for a bit in 1980.)


Steve
 
Reply With Quote
 
Niklas Holsti
Guest
Posts: n/a
 
      10-14-2010
Steve Pope wrote:
> Niklas Holsti <(E-Mail Removed)> wrote:
>
>> Steve Pope wrote:

> ...
>>> I am curious then if Ada generally facilitated separate compilation, and
>>> subsequent linking, of modules, in a C/C++ manner.

>> Yes, certainly....

>
> Thanks.


You are welcome, Steve.

> I have not really looked at Ada for 30 years. (Literally,
> I studied it for a bit in 1980.)


Nowadays the GNU Ada compiler GNAT makes it easy and cheap to use Ada.
See, for example, http://libre.adacore.com/. Also, comp.lang.ada is
alive and active.

--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
 
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
C++ reluctant to overload function Steve Pope C++ 43 10-15-2010 04:01 PM
Examples of using "reluctant" subexpressions in regexps? david.karr@wamu.net Java 4 04-27-2005 07:46 PM
Help simplify complex regexp needing positive lookahead and reluctant quantifers david.karr@wamu.net Java 7 03-25-2005 09:05 PM
function overload (not operator overload) Ying-Chieh Liao Perl Misc 3 10-11-2004 11:24 AM
How use the overload of>> (or<<) of a class in the overload of << and >> of another class? Piotre Ugrumov C++ 3 01-25-2004 08:08 PM



Advertisments