Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:58:20+00:00 2026-06-06T04:58:20+00:00

I have the following function: func addCatsToMap(m map[string][]CatHouse, meowId int, treats Set, dog *Dog)

  • 0

I have the following function:

func addCatsToMap(m map[string][]CatHouse, meowId int, treats Set, dog *Dog) {

//if (complicated thing) add Cat to m

}

where Set, the type of treats, is an interface with the following definition:

type Set interface {
  Add(value string)
  Contains(value string) (bool)
  Length() (int)
  RemoveDuplicates()
}

Question:

Is it true that m, treats, and dog are passed-by-reference, and meowId has it’s value copied?

I assume that:

  • m is pass-by-reference because it’s a map
  • dog is a struct. So, I should pass the pointer to avoid copying the data
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:58:21+00:00Added an answer on June 6, 2026 at 4:58 am

    An interface type is simply a set of methods. Notice that the members of an interface definition do not specify whether or not the receiver type is a pointer. That is because the method set of a value type is a subset of the method set of its associated pointer type. That’s a mouthful. What I mean is, if you have the following:

    type Whatever struct {
        Name string
    }
    

    and you define the following two methods:

    func (w *Whatever) Foo() {
        ...
    }
    
    func (w Whatever) Bar() {
        ...
    }
    

    Then the type Whatever has only the method Bar(), while the type *Whatever has the methods Foo() and Bar(). That means if you have the following interface:

    type Grits interface {
        Foo()
        Bar()
    }
    

    Then *Whatever implements Grits but Whatever does not, because Whatever lacks the method Foo(). When you define the input to a function as an interface type, you have no idea whether it’s a pointer or a value type.

    The following example illustrates a function that takes an interface type in both ways:

    package main
    
    import "fmt"
    
    type Fruit struct {
        Name string
    }
    
    func (f Fruit) Rename(name string) {
        f.Name = name
    }
    
    type Candy struct {
        Name string
    }
    
    func (c *Candy) Rename(name string) {
        c.Name = name
    }
    
    type Renamable interface {
        Rename(string)
    }
    
    func Rename(v Renamable, name string) {
        v.Rename(name)
        // at this point, we don't know if v is a pointer type or not.
    }
    
    func main() {
        c := Candy{Name: "Snickers"}
        f := Fruit{Name: "Apple"}
        fmt.Println(f)
        fmt.Println(c)
        Rename(f, "Zemo Fruit")
        Rename(&c, "Zemo Bar")
        fmt.Println(f)
        fmt.Println(c)
    }
    

    you could call Raname(&f, "Jorelli Fruit") but not Rename(c, "Jorelli Bar"), because both Fruit and *Fruit implement Renamable, while *Candy implements Renable and Candy does not.

    http://play.golang.org/p/Fb-L8Bvuwj

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function: func fitrange(a, x, b int) int { if a
I have the following higher-order function: public static Func<T, bool> Not<T>(Func<T, bool> otherFunc) {
I have a simple function as the following: static Task<A> Peirce<A, B>(Func<Func<A, Task<B>>, Task<A>>
I have the following function set up to sequentially fade in divs (with class
I have the following definition of a boost::function object: typedef boost::function<std::string (std::string, std::string)> concat;
Say I have the following code: (defn ^{:graph-title Function 1} func-1 [x] (do-something-with x))
Assume you have the following update: Update table set col1 = func(col2) where col1<>func(col2)
If I have the following function: def intercept(func): # do something here @intercept(arg1=20) def
I have added the following method to the Array prototype: Array.prototype.foreach = function(func){ for(var
I have following function in one Activity public void AppExit() { Editor edit =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.