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 9071295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:52:29+00:00 2026-06-16T17:52:29+00:00

I am just learning Go and wrote the following struct ( Image ) to

  • 0

I am just learning Go and wrote the following struct (Image) to implement the image.Image interface.

package main

import (
    "image"
    "image/color"
    "code.google.com/p/go-tour/pic"
)

type Image struct{}

func (img Image) ColorModel() color.Model {
    return color.RGBAModel
}

func (img Image) Bounds() image.Rectangle {
    return image.Rect(0, 0, 100, 100)
}

func (img Image) At(x, y int) color.Color {
    return color.RGBA{100, 100, 255, 255}   
}

func main() {
    m := Image{}
    pic.ShowImage(m)
}

If I just import image/color and not import image, image.Rect is undefined. Why? Shouldn’t image/color already cover the methods and properties of image?

Also, if I change the function receivers from (img Image) to (img *Image), an error arises:

Image does not implement image.Image (At method requires pointer receiver)

Why is that? Doesn’t (img *Image) indicate a pointer receiver?

  • 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-16T17:52:31+00:00Added an answer on June 16, 2026 at 5:52 pm

    If you check out the source for the image package and its sub-packages, you will see that image/color does not depend on image at all, so it never imports it.

    image does however import image/color

    For the second part of your question, where you change all of the receivers to pointers, that means you should also be passing an Image pointer to ShowImage:

    func main() {
        m := Image{}
        pic.ShowImage(&m)
    }
    

    Methods defined on a pointer receiver must be accessed on a pointer. But methods defined on just the struct can be accessed from a pointer or the value.

    Here is some documentation explaining the difference between a pointer or a value receiver of a method:

    1. Should I define methods on values or pointers?
    2. Why do T and *T have different method sets?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning C, and wrote my hello world program: #include <stdio.h> main()
I just started learning C, and wrote my hello world program: #include <stdio.h> main()
I wrote the following script Basically, I'm just learning Python for Machine Learning and
I just started learning how to write htaccess . I got the following code
Just learning C#, radiobuttons and checkboxes. No urgency. The code works to display the
While learning for an exam, I've just found the following task in an exercise:
I'm just learning Haskell and I am trying to write some code that simply
I've just started learning Clojure, if I define the following map: (def distributions {:normal
I just started learning C++ and I wrote this sample program from the text
I am just starting learning about Linq. I wrote some examples but there is

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.