Возникли проблемы с использованием классов / конструкторов при поиске расстояния между 2 точками - PullRequest
0 голосов
/ 02 марта 2020

Я пытаюсь объявить класс точки, который затем перегружается двойным х и двойным у. поздно, когда я создаю больше этого типа и присваиваю ему значения x и y, я получаю ошибку "неопределенная ссылка на` Point :: Point (double, double) '"для" Point pointOne (1.0, 1.0); " и "Point pointSpace (11.0, -8.0);" Я спросил своего учителя о моем конструкторе по умолчанию, и он предположительно настроен правильно. Я в растерянности из-за того, что мне следует делать.

Вот мой главный. cpp

    int main() {

    Point pointZero;
    Point pointOne(1.0, 1.0);
    Point pointSpace(11.0, -8.0);

    // test zero Point object
    assert(pointZero.getX() == 0.0);
    assert(pointZero.getY() == 0.0);

    // test one Point object
    assert(pointOne.getX() == 1.0);
    assert(pointOne.getY() == 1.0);

    // test the distance between the zero point and the one point
    assert(logically_equal(pointOne.distance(pointZero), 1.41421));

    // test the distance between the zero point and the space point
    assert(logically_equal(pointOne.distance(pointSpace), 13.4536));

    return 0;
}

inline bool logically_equal(double a, double b, double error_factor) {
    return a == b
            || abs(a - b)
                    < abs(std::min(a, b))
                            * std::numeric_limits<double>::epsilon()
                            * error_factor;
}

Точка. cpp файл (я еще не закончил написание функции для расстояния еще)

    #include "Point.h"

/** default constructor **/
Point::Point(){
    // TODO Auto-generated constructor stub
    this->x = 0.0;
    this->y = 0.0;
}

Point::~Point() {
    // TODO Auto-generated destructor stub

}

double Point::getX() const {
    return x;
}

double Point::getY() const {
    return y;
}


double Point::distance(const Point &p) const{

    //return double z = double sqrt((double pow(x - p),2) + (double pow(y - p),2));

}

и мой Point.h

#ifndef POINT_H_
#define POINT_H_

#include <iostream>

class Point {
public:
    /**
     * Constructors and destructor
     */
    Point();
    Point(const double x, const double y);
    virtual ~Point();

    /**
     * Get the x value
     */
    double getX() const;

    /**
     * Get the y value
     */
    double getY() const;

    /**
     * Return the distance between Points
     */
    double distance(const Point &p) const;

private:
    double x;
    double y;
};

#endif /* POINT_H_ */
...