>
> The declared type does not inherit any methods 
> <https://golang.org/ref/spec#Method_declarations> bound to the existing 
> type, but the method set <https://golang.org/ref/spec#Method_sets> of an 
> interface type or of elements of a composite type remains unchanged:


https://golang.org/ref/spec#Type_declarations

You need to use another strategy like struct embedding which *may *or *may 
not* work depending to your use case

A field declared with a type but no explicit field name is an *anonymous 
> field*, also called an *embedded* field or an embedding of the type in 
> the struct. An embedded type must be specified as a type name T or as a 
> pointer to a non-interface type name *T, and T itself may not be a 
> pointer type. The unqualified type name acts as the field name.


type xadvanced struct {
    *x
}
func(x *xadvanced)increment(){
   x.y ++
   fmt.Println(x.y)
}

I'd advise you do read the spec at least once, it's short and concise .


Le vendredi 2 décembre 2016 16:25:50 UTC+1, Slawomir Pryczek a écrit :
>
> Hi Guys,
>
> i want to make something like this
>
> type si struct {
>
>     s *sync_task.Sync_task
>
> }
>
>
> func (this *si) Process() {
>
>
>    ... some code here ...
>
>    this.Process();
>
> }
>
>
>
> Basically i want to extend object in another package... and this works. 
> Now i'd just want to extend it without creating "real" struct, code
>
> type x struct {
> y int
> }
> type xadvanced *x
>
> func (this *x) increment() {
> this.y++
> fmt.Println(this.y)
> }
>
> test2 := xadvanced(&test)
> test2.increment() ---> ERROR
>
> https://play.golang.org/
>
> What im doing wrong and how to access methods of x object when having 
> pointer to xadvanced...
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to