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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:19:23+00:00 2026-05-28T05:19:23+00:00

To get a bit of practice with OOP i’m trying to make a Point

  • 0

To get a bit of practice with OOP i’m trying to make a Point class (has 2 ints, x & y) and a Line class (has 2 Points).

Now when i go to build my main.cpp i get errors like..

“undefined reference to `Point::Point(float, float)’ “ and

” undefined reference to `Line::Line(Point, Point)'”

At a loss as to why, perhaps you could take a brief look at my files? It’d be much appreciated!

Main.cpp

#include "Point.hpp"
#include "Line.hpp"
#include <iostream>

using namespace std;

int main()
{
    Point p1(2.0f, 8.0f); // should default to (0, 0) as specified
    Point p2(4.0f, 10.0f);  // should override default

    p1.setX(17);


    if ( p1.atOrigin() && p2.atOrigin() )
        cout << "Both points are at origin!" << endl;
    else
    {
        cout << "p1 = ( " << p1.getX() << " , " << p1.getY() << " )" <<endl;
        cout << "p2 = ( " << p2.getX() << " , " << p2.getY() << " )" <<endl;
    }

    Line line(p1, p2);
    Point midpoint = line.midpoint();
    cout << "p1 = ( " << midpoint.getX() << " , " << midpoint.getY() << " )" <<endl;
    return 0;
}

Line.hpp

#ifndef _LINE_HPP_
#define _LINE_HPP_

#include "Point.hpp"

class Line{
public:
    Line(Point p1, Point p2);
    //void setp1(Point p1);
    //void setp2(Point p2);
    //Point getp1 finish

    Point midpoint();
    int length();

private:
    int _length;
    Point _midpoint;
    Point _p1, _p2;
};

#endif

Line.cpp

#include "Line.hpp"
#include <math.h>

Line::Line(Point p1, Point p2) : _p1(p1), _p2(p2)
{
}
Point Line::midpoint()
{
    _midpoint.setX() = (_p1.getX()+ _p2.getX()) /2;
    _midpoint.setY() = (_p1.getY()+ _p2.getY()) /2;
}
int Line::length()
{
    //a^2 + b^2 = c^2

    _length = sqrt( ( (pow( _p2.getX() - _p1.getX(), 2 ))
                     +(pow( _p2.getY() - _p1.getY(), 2 )) ) );
}

Point.hpp

#ifndef _POINT_HPP_
#define _POINT_HPP_

class Point {
public:
    Point( float x = 0, float y = 0);
    float getX() const;
    float getY() const;
    void setX(float x = 0);
    void setY(float y = 0);
    void setXY(float x = 0, float y = 0);
    bool atOrigin() const;

private:
    float _x, _y;

};

#endif

Point.cpp

#include "Point.hpp"

Point::Point(float x, float y) : _x(x), _y(y)
{
}

float Point::getX() const
{
    return _x;
}
float Point::getY() const
{
    return _y;
}
void Point::setX(float x)
{
    //if (x >= 0 &&
    _x = x;
}
void Point::setY(float y)
{
    //might want to check
    _y = y;
}
void Point::setXY(float x , float y )
{
    setX(x);
    setY(y);
}
bool Point::atOrigin() const
{
    if ( _x == 0 && _y == 0)
        return true;

    return false;
}
  • 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-28T05:19:24+00:00Added an answer on May 28, 2026 at 5:19 am

    In C++, not only do you have to compile main.cpp, but you also have to compile your Line.cpp and Point.cpp files. Then, when you have them all compiled into object files, you must link the object files together. This is handled automatically by some other languages such as Java.

    The exact instructions on how to do this will depend on which development environment you are using.

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

Sidebar

Related Questions

I'm having a bit of trouble trying to get class variables to work in
I'm trying to recreate the inbuilt vector class in cpp to get a bit
I'm trying to get the following bit of code to work in LINQPad but
I am trying to get the DB2 data provider from a 32-bit .Net application
I have a question about PHP Class. I am trying to get the result
I'm trying to get what I think is a really nice bit of HTML5
I'm starting to get a bit desperate in my attempts to get a ruby
Scrollbars get quite a bit of use in the site i'm working on and
Where can I get the 64 bit bootstrapper for SQL Server Express 2005 64
In order to get my setup a bit closer to one click deployment, I

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.