472,122 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

C# 14.5.5.1: what means "all methods declared in a base type of T are removed"?

Method invocation will consist of the following steps:

1. Member lookup (14.3) - evaluate method group set (Base.f() and
Derived.f()) .Standart say:
"The compile-time processing of a method invocation of the form M(A), where
M is a method group and A is
an optional argument-list, consists of the following steps:
 The set of candidate methods for the method invocation is constructed.
Starting with the set of methods
associated with M, which were found by a previous member lookup (14.3),
...."

2. Remove non-applicable methods and methods of base classes. In this
example both Base.f() and Derived.f() are applicable. Standart say:
"... the set is reduced to those
methods that are applicable with respect to the argument list A. The set
reduction consists of applying
the following rules to each method T.N in the set, where T is the type in
which the method N is declared:
If N is not applicable with respect to A (14.4.2.1), then N is removed from
the set.
If N is applicable with respect to A (14.4.2.1), then all methods declared
in a base type of T are removed
from the set."

But what mean words "then all methods declared in a base type of T are
removed from the set"? If all methods must be removed than test() method in
example must invoke Derived.f(), but MSVC# invoke Base.f(). Why? Any
suggestions.

class Source
{
static public implicit operator Target ( Source source )
{ return new Target(); }
}

class Target
{}

class Base
{
public void f ( Source source )
{}
}

class Derived : Base
{
public void f ( Target target ) // this function is applicable
(user-defined implicit conversion used)
{}

public void test()
{
Source source = new Source();
f ( source ); // invoke Base.f() - why?
}
}

Alex.
Nov 16 '05 #1
4 1425
Alex Sedow wrote:
Method invocation will consist of the following steps:

1. Member lookup (14.3) - evaluate method group set (Base.f() and
Derived.f()) .Standart say:
"The compile-time processing of a method invocation of the form M(A), where
M is a method group and A is
an optional argument-list, consists of the following steps:
 The set of candidate methods for the method invocation is constructed.
Starting with the set of methods
associated with M, which were found by a previous member lookup (14.3),
..."

2. Remove non-applicable methods and methods of base classes. In this
example both Base.f() and Derived.f() are applicable. Standart say:
"... the set is reduced to those
methods that are applicable with respect to the argument list A. The set
reduction consists of applying
the following rules to each method T.N in the set, where T is the type in
which the method N is declared:
If N is not applicable with respect to A (14.4.2.1), then N is removed from
the set.
If N is applicable with respect to A (14.4.2.1), then all methods declared
in a base type of T are removed
from the set."

But what mean words "then all methods declared in a base type of T are
removed from the set"? If all methods must be removed than test() method in
example must invoke Derived.f(), but MSVC# invoke Base.f(). Why? Any
suggestions.

class Source
{
static public implicit operator Target ( Source source )
{ return new Target(); }
}

class Target
{}

class Base
{
public void f ( Source source )
{}
}

class Derived : Base
{
public void f ( Target target ) // this function is applicable
(user-defined implicit conversion used)
{}

public void test()
{
Source source = new Source();
f ( source ); // invoke Base.f() - why?
}
}


In my test, Derived.test() invokes Derived.f().

--
mikeb
Nov 16 '05 #2
Alex Sedow wrote:
Method invocation will consist of the following steps:

1. Member lookup (14.3) - evaluate method group set (Base.f() and
Derived.f()) .Standart say:
"The compile-time processing of a method invocation of the form M(A), where
M is a method group and A is
an optional argument-list, consists of the following steps:
 The set of candidate methods for the method invocation is constructed.
Starting with the set of methods
associated with M, which were found by a previous member lookup (14.3),
..."

2. Remove non-applicable methods and methods of base classes. In this
example both Base.f() and Derived.f() are applicable. Standart say:
"... the set is reduced to those
methods that are applicable with respect to the argument list A. The set
reduction consists of applying
the following rules to each method T.N in the set, where T is the type in
which the method N is declared:
If N is not applicable with respect to A (14.4.2.1), then N is removed from
the set.
If N is applicable with respect to A (14.4.2.1), then all methods declared
in a base type of T are removed
from the set."

But what mean words "then all methods declared in a base type of T are
removed from the set"? If all methods must be removed than test() method in
example must invoke Derived.f(), but MSVC# invoke Base.f(). Why? Any
suggestions.

class Source
{
static public implicit operator Target ( Source source )
{ return new Target(); }
}

class Target
{}

class Base
{
public void f ( Source source )
{}
}

class Derived : Base
{
public void f ( Target target ) // this function is applicable
(user-defined implicit conversion used)
{}
That's not true. The convertion is applied when you
call the method. So you still have 2 distinct methods:

f(Source)
f(Target)

public void test()
{
Source source = new Source();
f ( source ); // invoke Base.f() - why?


because f(Source) is still visible and it is the best match.

Bye
Rob
Nov 16 '05 #3
"mikeb" <ma************@nospam.mailnull.com> wrote in message
news:#a**************@TK2MSFTNGP11.phx.gbl...

In my test, Derived.test() invokes Derived.f().

--
mikeb


You right. Sorry. I not there have seen.

Alex.
Nov 16 '05 #4
"Robert Jordan" <ro*****@gmx.net> wrote in message
news:ch*************@news.t-online.com...
That's not true. The convertion is applied when you
call the method. So you still have 2 distinct methods:

f(Source)
f(Target)

public void test()
{
Source source = new Source();
f ( source ); // invoke Base.f() - why?


because f(Source) is still visible and it is the best match.

Bye
Rob


I not there have seen.
f ( source ) invoke Derived.f().

Alex.
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by cppaddict | last post: by
5 posts views Thread by Duck Dodgers | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.