Linked by Hadrien Grasland on Wed 15th Jun 2011 07:32 UTC, submitted by ebasconp
General Development "The recently finished C++ ISO standard, with the working name of C++0x, is due to be published this summer, following the finishing touches to the ISO spec language and standards wonks agreed upon in March."
Thread beginning with comment 477641
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE[10]: Basically, awesome
by FealDorf on Fri 17th Jun 2011 23:51 UTC in reply to "RE[9]: Basically, awesome"
FealDorf
Member since:
2008-01-07

From what I can remember, only Eiffel (and descendants) provides a complete solution for the problem of method-collision.

And if you do the same in other languages, it will/may cause a runtime or compiletime error. Why? Cuz unless we're also compiling code where you pass a C1 object into a method which accepts A1 object, you are less likely to face an issue. But in Go, no such strict description is required that C1 *must* implement every method of A1 or A2.

Reply Parent Score: 1

RE[11]: Basically, awesome
by moondevil on Sat 18th Jun 2011 06:42 in reply to "RE[10]: Basically, awesome"
moondevil Member since:
2005-07-08

But in Go, no such strict description is required that C1 *must* implement every method of A1 or A2.


Then I have an exercise for you. Remove the comment from the interface A2 and make the code compile according to your description.


package main

import "fmt"

type A1 interface {
SayHi (int)
}

type A2 interface {
SayHo (string)
//CompileError(int)
}

type C1 struct {
}

func (self *C1) SayHi (count int) {
fmt.Printf ("C says %d\n", count)
}

func (self *C1) SayHo (name string) {
fmt.Printf ("C says %s\n", name)
}

func UseA1 (val A1) {
val.SayHi (30)
}

func UseA2 (val A2) {
val.SayHo ("John")
}

func main () {
c := new(C1)
c.SayHi(25)
c.SayHo("Mike")
UseA1(c)
UseA2(c)
}

Reply Parent Score: 2

RE[12]: Basically, awesome
by FealDorf on Sat 18th Jun 2011 13:45 in reply to "RE[11]: Basically, awesome"
FealDorf Member since:
2008-01-07

That's the exact point I'm making.
You tried to pass an object of C1 to an interface of A2.

That is, the class itself has no requirement to adhere to any interface. *Why* should an object of C1 implement A2?

Edited 2011-06-18 14:02 UTC

Reply Parent Score: 1