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
Sorry if this has been asked, I am not sure how to best word
(I’m sorry if this has been asked before; the search feature seems to be
[I'm not sure if this question has been asked, though I've looked around a
Sorry if this has already been asked, but I just want to make sure
Sorry if you feel like this has been asked but I have read the
I'm sure this has been answered somewhere, already, but I just can't find it:
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry for the slightly rubbish title. I could not think how to describe this
Sorry for the second newbie question, I'm a developer not a sysadmin so this

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.