By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,805 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,805 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
"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.