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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:12:07+00:00 2026-05-14T07:12:07+00:00

I have a Point2D class as follows: class Point2D{ int x; int y; public:

  • 0

I have a Point2D class as follows:

class Point2D{
        int x;
        int y;
    public:
        Point2D(int inX, int inY){
            x = inX;
            y = inY;
        };

        int getX(){return x;};
        int getY(){return y;};
    };

Now I have defined a class Line as:

class Line {
Point2D p1,p2;
public:
 LineVector(const Point2D &p1,const Point2D &p2):p1(p1),p2(p2) {
        int x1,y1,x2,y2;
        x1=p1.getX();y1=p1.getY();x2=p2.getX();y2=p2.getY();
 }
};

Now the compiler gives the error in the last line( where getX() etc are called):

error: passing const Point2D as this argument of int Point2D::getX() discards qualifiers

If I remove the const keyword at both places, then it compiles successfully.

What is the error? Is it because getX() etc are defined inline? Is there any way to rectify this retaining them inline?

  • 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-14T07:12:07+00:00Added an answer on May 14, 2026 at 7:12 am

    You have not declared getX() and getY() methods as const. In C++, you can only call const methods from a const object. So your function signature should be int getX() const{..}. By defining them as the const method you are telling the compiler that you are not going to modify any member variable inside this method. Since your object is a const object, it is not supposed to be modified hence you can call only call const methods on it.

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

Sidebar

Related Questions

I have this class class Point2D { public: bool isValid(); // ... private: double
I have a class as follows struct CliHandler { CliHandler(int argc, char** argv); ~CliHandler();
I have these two functions (with Point2D & LineVector (has 2 Point2D member variables)
I have the following code: public class Parent { public string MyField { get;
I have a singleton class that is instantiated as follows: #import FavoritesManager.h static FavoritesManager
Suppose I have two classes a base class and an inherited class as follows:
I currently have this Fluent NHibernate configuration: public class NHibernateConfig { public static Configuration
Right now, I have: public <T> T[] toArray(T[] old) { T[] arr = Arrays.copyOf(old,
Case One Say you have a little class: class Point3D { private: float x,y,z;
I have a C++ class that contains a non-copyable handle. The class, however, must

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.