Код: Выделить всё
point.h:
#pragma once
#ifndef POINT_H
#define POINT_H
#include
struct point {
double x;
double y;
};
double abs(point const&);
#endif
Код: Выделить всё
point.cpp:
#include "point.h"
double abs(point const& p) {
return std::sqrt(p.x * p.x + p.y * p.y);
}
Код: Выделить всё
ellipse.h:
#pragma once
#ifndef ELLIPSE_H
#define ELLIPSE_H
#include "point.cpp"
class ellipse {
private:
point focus1, focus2;
double MajorAxis;
public:
ellipse(point const&, point const&, double const&);
};
#endif
Код: Выделить всё
ellipse.cpp:
#include "ellipse.h"
ellipse::ellipse(point const& F1, point const& F2, double const& a) {
focus1 = F1;
focus2 = F2;
MajorAxis = a;
}
Код: Выделить всё
#include "ellipse.cpp"
#include "point.cpp"
int main() {
ellipse E = ellipse({3, 0}, {0, 4}, 7);
}
Код: Выделить всё
In file included from main.cpp:2:
point.cpp:3:8: error: redefinition of 'double abs(const point&)'
double abs(point const& p) {
^~~
In file included from ellipse.h:5,
from ellipse.cpp:1,
from main.cpp:1:
point.cpp:3:8: note: 'double abs(const point&)' previously defined here
double abs(point const& p) {
^~~
Подробнее здесь: https://stackoverflow.com/questions/782 ... en-when-us