Thread overview
question: covariance
Sep 04, 2003
Andy Friesen
September 03, 2003
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


September 04, 2003
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

September 04, 2003
"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