www.digitalmars.com         C & C++   DMDScript  

D - question: covariance

reply "Carlos Santander B." <carlos8294 msn.com> writes:
What's the reasoning behind this?

class A { void foo() { ... } }
class B : A { int foo() { ... } }

"function foo overrides but is not covariant with foo"

-------------------------
Carlos Santander
What's the reasoning behind this?

class A { void foo() { ... } }
class B : A { int foo() { ... } }

"function foo overrides but is not covariant with foo"

-------------------------
Carlos Santander
Sep 03 2003
parent reply Andy Friesen <andy ikagames.com> writes:
Carlos Santander B. wrote:
 What's the reasoning behind this?
 
 class A { void foo() { ... } }
 class B : A { int foo() { ... } }
 
 "function foo overrides but is not covariant with foo"
 
 -------------------------
 Carlos Santander
 What's the reasoning behind this?
 
 class A { void foo() { ... } }
 class B : A { int foo() { ... } }
 
 "function foo overrides but is not covariant with foo"
B.foo can't override A.foo, because it has a different (and not covariant) return type, and it can't be a simple overload, because they have the same argument list. Thus, error. :) -- andy
Sep 03 2003
parent "Carlos Santander B." <carlos8294 msn.com> writes:
"Andy Friesen" <andy ikagames.com> wrote in message
news:bj6aij$1s98$1 digitaldaemon.com...
|
| B.foo can't override A.foo, because it has a different (and not
| covariant) return type, and it can't be a simple overload, because they
| have the same argument list.  Thus, error. :)
|
|   -- andy
|

Thanks, I hadn't noticed that.

-------------------------
Carlos Santander


---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 2003-09-01
Sep 03 2003