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

  • Home
  • SEARCH
  • 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 3795444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:05:05+00:00 2026-05-19T13:05:05+00:00

Sorry not sure if this has been asked before, I really dont know what

  • 0

Sorry not sure if this has been asked before, I really dont know what to look up either. I’m new to C++ from Java. When we want to call a function on an object in Java, we say picture.rotateRight();

Then, in rotateRight(), we’d have something like int height=this.getHeight();. However, how do we do this in C++? I have a method named invertcolors(); and then I have something like:

Image* myImage = new Image();
bool b = myImage->ReadFromFile("in_01.bmp");
myImage->invertcolors();

void invertcolors(){
    int width=TellWidth();
    int height=TellHeight();
    ...
}

How do I access myImage from the method definition without actually saying myImage (since that name can later be changed).

Also, the function parameters are non-negotiable.

  • 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-05-19T13:05:06+00:00Added an answer on May 19, 2026 at 1:05 pm

    First of all, your invertcolors() function definition is a non-member function. Although you’ve declared it inside the Image class, you haven’t linked the implementation to the class in any way so the compiler thinks its a non-member function. To make it a member of Image, you need to use Image::invertcolors like this:

    void Image::invertcolors(){
        int width=TellWidth();
        int height=TellHeight();
        ...
    }
    

    You do get this in C++, but it’s a pointer so you have to use this->getHeight() in C++. However, note that it is redundant in this case. As a beginner you’ll probably find the only real use in a method having the same argument name as an attribute. In this case, you’ll need to use this->height = height for example. However, note that C++ has a nice syntax addition here. This code does the same as a simple setter:

    void Image::setHeight(int height): height(height) {}
    

    Note that neither in Java nor C++ is this an operator. ., -> and + are examples of operators.

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

Sidebar

Related Questions

So, if this question has been asked before, I'm sorry. I'm not exactly sure
I'm sorry if this question has been asked before, but I'm not even sure
Sorry if this has been asked, I am not sure how to best word
Sorry if this has been asked and answered in full somewhere. Not sure if
[I'm not sure if this question has been asked, though I've looked around a
Sorry if this has been answered somewhere; I'm not quite sure how to phrase
Sorry if this has been asked before, I can't seem to find anything. I'm
Sorry if this has already been asked, but I just want to make sure
Sorry if this has been asked before - there's a question with a similar
Sorry, I'm not really sure of the right way to ask this one so

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.