Непонятные ошибки компиляции
13.12.2014, 13:38. Показов 1286. Ответов 2
rectangle.h:
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #ifndef RECTANGLE_H
#define RECTANGLE_H
#include <string>
using namespace std;
class Rectangle
{
friend class Factory;
public:
Rectangle(string i = "", float x1_ = 0, float y1_ = 0, float x2_ = 0, float y2_ = 0,
float x3_ = 0, float y3_ = 0, float x4_ = 0, float y4_ = 0);
Rectangle(const Rectangle &right);
void Clear();
bool IsEmpty();
friend ostream& operator << (ostream &out, const Rectangle &right);
void Move(float dx, float dy);
bool IsInclude(const Rectangle &right) const;
bool IsInclude(const Pentagon &right) const;
static bool IsRectangle(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
protected:
string id;
float x1, y1, x2, y2, x3, y3, x4, y4;
float minX() const;
float minY() const;
float maxX() const;
float maxY() const;
static float d(float x1, float y1, float x2, float y2);
static const float E; // точность - вычисленные дробные числа нельзя сравнивать, т.к. очень часто есть погрешность.
// поэтому проверяем, чтобы модуль разности чисел был меньше точности
};
#endif |
|
rectangle.cpp:
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
| #include "rectangle.h"
#include "pentagon.h"
#include <iostream>
using namespace std;
Rectangle::Rectangle(string i, float x1_, float y1_, float x2_, float y2_, float x3_, float y3_, float x4_, float y4_)
{
id = i;
if (IsRectangle(x1_, y1_, x2_, y2_, x3_, y3_, x4_, y4_))
{
x1 = x1_;
y1 = y1_;
x2 = x2_;
y2 = y2_;
x3 = x3_;
y3 = y3_;
x4 = x4_;
y4 = y4_;
}
else
x1 = x2 = x3 = x4 = y1 = y2 = y3 = y4 = 0;
}
bool Rectangle::IsRectangle(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
{
if (abs(d(x1, y1, x4, y4) - d(x2, y2, x3, y3)) <= E && abs(d(x1, y1, x2, y2) - d(x3, y3, x4, y4)) <= E &&
abs(d(x1, y1, x3, y3) - d(x2, y2, x4, y4)) <= E) // у прямоугольника равны противоположные стороны и диагонали. сравниваем разность с точностью
return true;
else
return false;
}
float Rectangle::d(float x1, float y1, float x2, float y2)
{
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
const float Rectangle::E = 10e-7;
Rectangle::Rectangle(const Rectangle &right)
{
x1 = right.x1;
y1 = right.y1;
x2 = right.x2;
y2 = right.y2;
x3 = right.x3;
y3 = right.y3;
x4 = right.x4;
y4 = right.y4;
}
ostream& operator << (ostream &out, const Rectangle &right)
{
out << "(" << right.x1 << ", " << right.y1 << "), (" << right.x2 << ", " << right.y2 << "), ("
<< right.x3 << ", " << right.y3 << "), (" << right.x4 << ", " << right.y4 << ")";
return out;
}
void Rectangle::Move(float dx, float dy)
{
x1 += dx, x2 += dx, x3 += dx, x4 += dx;
y1 += dy, y2 += dy, y3 += dy, y4 += dy;
}
bool Rectangle::IsInclude(const Rectangle &right) const
{
if (minX() <= right.minX() && maxX() >= right.maxX() &&
minY() <= right.minY() && maxY() >= right.maxY()) // если проекция второй фигуры входит в проекцию первой фигуры на каждой оси,
// то вторая фигура входит в первую
return true;
else
return false;
}
bool Rectangle::IsInclude(const Pentagon &right) const
{
if (minX() <= right.minX() && maxX() >= right.maxX() &&
minY() <= right.minY() && maxY() >= right.maxY()) // если проекция второй фигуры входит в проекцию первой фигуры на каждой оси,
// то вторая фигура входит в первую
return true;
else
return false;
}
float Rectangle::minX() const
{
float res = x1;
if (x2 <= res)
res = x2;
if (x3 <= res)
res = x3;
if (x4 <= res)
res = x4;
return res;
}
float Rectangle::maxX() const
{
float res = x1;
if (x2 >= res)
res = x2;
if (x3 >= res)
res = x3;
if (x4 >= res)
res = x4;
return res;
}
float Rectangle::maxY() const
{
float res = y1;
if (y2 >= res)
res = y2;
if (y3 >= res)
res = y3;
if (y4 >= res)
res = y4;
return res;
}
float Rectangle::minY() const
{
float res = y1;
if (y2 <= res)
res = y2;
if (y3 <= res)
res = y3;
if (y4 <= res)
res = y4;
return res;
}
void Rectangle::Clear()
{
x1 = 0, x2 = 0, x3 = 0, x4 = 0;
y1 = 0, y2 = 0, y3 = 0, y4 = 0;
}
bool Rectangle::IsEmpty()
{
return (x1 == 0 && x2 == 0 && x3 == 0 && x4 == 0 &&
y1 == 0 && y2 == 0 && y3 == 0 && y4 == 0);
} |
|
pentagon.h:
| C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| #ifndef PENTAGON_H
#define PENTAGON_H
#include "rectangle.h"
#include <string>
using namespace std;
class Pentagon : public Rectangle
{
friend class Factory;
friend class Rectangle;
public:
Pentagon(string i = "", float x1_ = 0, float y1_ = 0, float x2_ = 0, float y2_ = 0,
float x3_ = 0, float y3_ = 0, float x4_ = 0, float y4_ = 0, float x5_ = 0, float y5_ = 0);
Pentagon(const Pentagon &right);
void Clear();
bool IsEmpty();
friend ostream& operator << (ostream &out, const Pentagon &right);
void Move(float dx, float dy);
bool IsInclude(const Pentagon &right) const;
protected:
float x5, y5;
float minX() const;
float minY() const;
float maxX() const;
float maxY() const;
};
#endif |
|
Ошибки (компилятор MS VS 2013):
| Code | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| 1>------ Сборка начата: проект: Работа, Конфигурация: Debug Win32 ------
1> rectangle.cpp
1>d:\с++\работа\работа\rectangle.h(21): error C4430: отсутствует спецификатор типа - предполагается int. Примечание. C++ не поддерживает int по умолчанию
1>d:\с++\работа\работа\rectangle.h(21): error C2143: синтаксическая ошибка: отсутствие "," перед "&"
1>d:\с++\работа\работа\rectangle.cpp(38): warning C4305: инициализация: усечение из "double" к "const float"
1>d:\с++\работа\работа\rectangle.cpp(76): error C2511: bool Rectangle::IsInclude(const Pentagon &) const: перегруженная функция-член не найдена в "Rectangle"
1> d:\с++\работа\работа\rectangle.h(8): см. объявление "Rectangle"
1>d:\с++\работа\работа\rectangle.cpp(77): error C2352: Rectangle::minX: недопустимый вызов нестатической функции-члена
1> d:\с++\работа\работа\rectangle.h(28): см. объявление "Rectangle::minX"
1>d:\с++\работа\работа\rectangle.cpp(77): error C2352: Rectangle::maxX: недопустимый вызов нестатической функции-члена
1> d:\с++\работа\работа\rectangle.h(30): см. объявление "Rectangle::maxX"
1>d:\с++\работа\работа\rectangle.cpp(78): error C2352: Rectangle::minY: недопустимый вызов нестатической функции-члена
1> d:\с++\работа\работа\rectangle.h(29): см. объявление "Rectangle::minY"
1>d:\с++\работа\работа\rectangle.cpp(78): error C2352: Rectangle::maxY: недопустимый вызов нестатической функции-члена
1> d:\с++\работа\работа\rectangle.h(31): см. объявление "Rectangle::maxY"
1> pentagon.cpp
1>d:\с++\работа\работа\rectangle.h(21): error C4430: отсутствует спецификатор типа - предполагается int. Примечание. C++ не поддерживает int по умолчанию
1>d:\с++\работа\работа\rectangle.h(21): error C2143: синтаксическая ошибка: отсутствие "," перед "&"
1>c1xx : fatal error C1903: не удается восстановить после предыдущих ошибок; остановка компиляции
1> main.cpp
1>d:\с++\работа\работа\rectangle.h(21): error C4430: отсутствует спецификатор типа - предполагается int. Примечание. C++ не поддерживает int по умолчанию
1>d:\с++\работа\работа\rectangle.h(21): error C2143: синтаксическая ошибка: отсутствие "," перед "&"
1>d:\с++\работа\работа\main.cpp(68): error C2664: "bool Pentagon::IsInclude(const Pentagon &) const": невозможно преобразовать аргумент 1 из "Rectangle" в "const Pentagon &"
1> Причина: невозможно преобразовать "Rectangle" в "const Pentagon"
1> Для выполнения данного преобразования нет доступного оператора преобразования, определенного пользователем, или вызов оператора невозможен
1>d:\с++\работа\работа\main.cpp(70): error C2664: "bool Pentagon::IsInclude(const Pentagon &) const": невозможно преобразовать аргумент 1 из "Rectangle" в "const Pentagon &"
1> Причина: невозможно преобразовать "Rectangle" в "const Pentagon"
1> Для выполнения данного преобразования нет доступного оператора преобразования, определенного пользователем, или вызов оператора невозможен
1> factory.cpp
1>d:\с++\работа\работа\rectangle.h(21): error C4430: отсутствует спецификатор типа - предполагается int. Примечание. C++ не поддерживает int по умолчанию
1>d:\с++\работа\работа\rectangle.h(21): error C2143: синтаксическая ошибка: отсутствие "," перед "&"
1> Создание кода...
========== Сборка: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ========== |
|
Причины возникновения сих ошибок мне совершенно неясны.
Почему в строчке "bool IsInclude(const Pentagon &right) const;" отсутствует спецификатор типа, когда все типы указаны?.. Ну и т.д. Что это все значит?
0
|