Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-const Color::operator[] should return mutable reference #575

Open
azeey opened this issue Feb 5, 2024 · 3 comments
Open

non-const Color::operator[] should return mutable reference #575

azeey opened this issue Feb 5, 2024 · 3 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@azeey
Copy link
Contributor

azeey commented Feb 5, 2024

Environment

  • OS Version: Ubuntu 22.04
  • Source or binary build? main, e0193a5

Description

  • Expected behavior: To be able to mutate a component of Color using operator[]
  • Actual behavior: Since it returns a value, any mutation is not applied to the component in Color
    public: float operator[](const unsigned int _index);
@azeey azeey added the bug Something isn't working label Feb 5, 2024
@azeey azeey added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 6, 2024
@azeey azeey moved this from Inbox to To do in Core development Feb 12, 2024
@Avisheet
Copy link

Avisheet commented Feb 21, 2024

The issue you're describing is related to the operator[] overload for the Color class. The problem is that the operator is declared to return a float instead of a reference to a float. As a result, when you use the operator to access a component of the color and attempt to mutate it, the mutation doesn't apply to the actual color instance.

To fix this issue, you should modify the declaration of the operator[] to return a reference to a float. Here's the corrected declaration:

public: float& operator[](const unsigned int _index);

This modification allows you to use the operator to both access and mutate the individual components of the Color class.

I hope by these changes in the code you will be able to mutate a component of color using operator

@aagrawal05
Copy link

Hi, is this issue still open? If it hasn't been implemented I would be happy to open the pull request.

@Avisheet
Copy link

Avisheet commented Apr 4, 2024

Hi @aagrawal05 , I am currently working on this issue. I'm getting some run time errors while running test cases. You can check those details here.
It would be appreciated if you can add some value to that .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
Status: To do
Development

No branches or pull requests

3 participants