G
29 августа 2021 г. 0:11

Ошибка undefined reference to

Доброго времени суток!

Полгода назад писал один проект на Qt, получил ошибку и так и не смог разобраться что там не так.

Не могли бы вы глянуть и указать на ошибки?

Ошибки

complex.h

  1. #ifndef COMPLEX_H
  2. #define COMPLEX_H
  3.  
  4. #include <QtMath>
  5.  
  6. class Complex
  7. {
  8. public:
  9. qreal real;
  10. qreal imag;
  11. bool inf;
  12.  
  13. Complex(const qreal &a=0, const qreal &b=0, const bool &c=1);
  14.  
  15. /*Complex(const Complex &a);
  16.  
  17. Complex operator = (const Complex &a);*/
  18.  
  19. //~Complex();
  20.  
  21. static qreal norm (const Complex &a);
  22.  
  23. static qreal abs (const Complex &a);
  24.  
  25. static qreal arg (const Complex &a);
  26.  
  27. static Complex conj (const Complex &a);
  28.  
  29. Complex operator - () const;
  30.  
  31. Complex operator + (const Complex &a) const;
  32.  
  33. Complex operator - (const Complex &a) const;
  34.  
  35. Complex operator * (const Complex &a) const;
  36.  
  37. Complex operator / (const Complex &a) const;
  38.  
  39. bool operator == (const Complex &a) const;
  40.  
  41. bool operator != (const Complex &a) const;
  42.  
  43. static Complex exp(const Complex &a);
  44.  
  45. static Complex ln(const Complex &a);
  46.  
  47. static Complex pow (const Complex &a, const Complex &b);
  48.  
  49. static Complex sin(const Complex &a);
  50.  
  51. static Complex cos(const Complex &a);
  52.  
  53. };
  54.  
  55. #endif

transformation.h

  1. #ifndef TRANSFORMATION_H
  2. #define TRANSFORMATION_H
  3.  
  4. #include "complex.h"
  5. #include <QVector>
  6. //#include "circle.h"
  7.  
  8. class Transformation
  9. {
  10. private:
  11. Complex a;
  12. Complex b;
  13. Complex c;
  14. Complex d;
  15. bool e;
  16.  
  17. public:
  18.  
  19. //конструктор
  20. Transformation(const Complex &a_1 = {1,0}, const Complex &b_1 = {0, 0}, const Complex &c_1 = {0, 0}, const Complex &d_1 = {1, 0}, const bool &e_1 = 0);
  21.  
  22. Complex Transf(const Complex &G) const;
  23.  
  24. //оператор композиции (последовательное применение)
  25. Transformation operator *(const Transformation &t) const;
  26.  
  27. //оператор итерации (последовательное примение одного преобразования несколько раз)
  28. Transformation operator ^(const int &k) const;
  29.  
  30. //оператор сравнения, возвращает true если преобразования одинаковы
  31. bool operator == (const Transformation &t) const;
  32.  
  33. //оператор сравнения, возвращает true если преобразования различны
  34. bool operator != (const Transformation &t) const;
  35.  
  36. //поворот(центр поворота, угол)
  37. static Transformation rotate(const Complex &O, const qreal &ang);
  38.  
  39. //static Transformation invers(Circle &G);
  40.  
  41. };
  42.  
  43.  
  44. #endif // TRANSFORMATION_H
  45.  

complex.cpp

  1. #include "complex.h"
  2.  
  3. Complex::Complex(const qreal &a, const qreal &b, const bool &c)
  4. : real{a}, imag{b}, inf{c}
  5. {
  6.  
  7. }
  8.  
  9. /*Complex::Complex(const Complex &a)
  10. : real{a.real}, imag{a.imag}, inf{a.inf}
  11. {
  12.  
  13. }
  14.  
  15. Complex Complex::operator =(const Complex &a)
  16. {
  17. real = a.real;
  18. imag = a.imag;
  19. inf = a.inf;
  20. return {a.real, a.imag, a.inf};
  21. }
  22. */
  23.  
  24. /*Complex::~Complex(){
  25. delete real, imag, inf;
  26. }*/
  27.  
  28. /*
  29. {
  30. if (a.inf)
  31. {
  32. out << a.real;
  33. if (a.imag==0){
  34. out << "+0i";
  35. } else {
  36. if (a.imag > 0)
  37. {
  38. out << "+";
  39. }
  40. out << a.imag << "i";
  41. }
  42. }
  43. else
  44. {
  45. out << "∞";
  46. }
  47. return out;
  48. }*/
  49.  
  50. qreal Complex::norm(const Complex &a)
  51. {
  52. return a.real * a.real + a.imag * a.imag;
  53. }
  54.  
  55. qreal Complex::abs(const Complex &a)
  56. {
  57. return qSqrt(Complex::norm(a));
  58. }
  59.  
  60. qreal Complex::arg(const Complex &a)
  61. {
  62. if (a.real == 0)
  63. {
  64. return ((a.real > 0) - (a.real < 0)) * qAcos(-1) / 2;
  65. }
  66. else if ((a.real < 0) && (a.imag > 0))
  67. {
  68. return qAcos(-1) + qAtan(a.imag / a.real);
  69. }
  70. else
  71. {
  72. return -qAcos(-1) + qAtan(a.imag / a.real);
  73. }
  74. }
  75.  
  76. Complex Complex::conj(const Complex &a)
  77. {
  78. return {a.real, -a.imag, a.inf};
  79. }
  80.  
  81. Complex Complex::operator -() const
  82. {
  83. if (inf)
  84. {
  85. return {-real,-imag};
  86. }
  87. else
  88. {
  89. return {0, 0, 0};
  90. }
  91. }
  92.  
  93. Complex Complex::operator+(const Complex &a) const
  94. {
  95. if ((inf) && (a.inf))
  96. {
  97. return {real + a.real, imag + a.imag};
  98. }
  99. else
  100. {
  101. return {0, 0, 0};
  102. }
  103. }
  104.  
  105. Complex Complex::operator-(const Complex &a) const
  106. {
  107. if ((inf) && (a.inf))
  108. {
  109. return {real - a.real, imag - a.imag};
  110. }
  111. else
  112. {
  113. return {0, 0, 0};
  114. }
  115. }
  116.  
  117. Complex Complex::operator*(const Complex &a) const
  118. {
  119. if ((inf) && (a.inf))
  120. {
  121. return {real * a.real - imag * a.imag, real * a.imag + imag * a.real};
  122. }
  123. else
  124. {
  125. return {0, 0, 0};
  126. }
  127. }
  128.  
  129. Complex Complex::operator/(const Complex &a) const
  130. {
  131. Complex out;
  132. if ((inf) && (a.inf))
  133. {
  134. if ((a.real == 0) && (a.imag == 0))
  135. {
  136. out={0, 0, 0};
  137. }
  138. else
  139. {
  140. Complex d = *this;
  141. Complex r = d * Complex::conj(a);
  142. out = {r.real / Complex::norm(a), r.imag / Complex::norm(a)};
  143. }
  144. }
  145. else if (inf)
  146. {
  147. out = {0, 0, 1};
  148. }
  149.  
  150. return out;
  151. }
  152.  
  153. bool Complex::operator==(const Complex &a) const
  154. {
  155. if ((real == a.real) && (imag == a.imag) && (inf == a.inf))
  156. {
  157. return true;
  158. }
  159. else
  160. {
  161. return false;
  162. }
  163. }
  164.  
  165. bool Complex::operator!=(const Complex &a) const
  166. {
  167. if ((real - a.real != 0) || (imag - a.imag != 0) || (inf - a.inf != 0))
  168. {
  169. return true;
  170. }
  171. else
  172. {
  173. return false;
  174. }
  175. }
  176.  
  177. Complex Complex::exp(const Complex &a)
  178. {
  179. if (a.inf)
  180. {
  181. return {qExp(a.real) * qCos(a.imag), qExp(a.real) * qSin(a.imag)};
  182. }
  183. else
  184. {
  185. return {0, 0, 0};
  186. }
  187. }
  188.  
  189. Complex Complex::ln(const Complex &a)
  190. {
  191. if ((a.real==0)&&(a.imag==0))
  192. {
  193. return {0,0,0};
  194. }
  195. else
  196. {
  197. return {qLn(Complex::abs(a)), qAcos(a.real / Complex::abs(a))};
  198. }
  199. }
  200.  
  201. Complex Complex::pow(const Complex &a, const Complex &b)
  202. {
  203. return (Complex::exp(Complex::ln(a) * b));
  204. }
  205.  
  206. Complex Complex::sin(const Complex &a)
  207. {
  208. return (Complex::exp(Complex(0, 1) * a) - Complex::exp(Complex(0, -1) * a)) / Complex(0, 2);
  209. }
  210.  
  211. Complex Complex::cos(const Complex &a)
  212. {
  213. return (Complex::exp(Complex(0, 1) * a) + Complex::exp(Complex(0, -1) * a)) / Complex(2, 0);
  214. }
  215.  

transformation.cpp

  1. #include "transformation.h"
  2.  
  3. Transformation::Transformation(const Complex &a_1, const Complex &b_1, const Complex &c_1, const Complex &d_1, const bool &e_1)
  4. : a{a_1}, b{b_1}, c{c_1}, d{d_1}, e{e_1}
  5. {
  6.  
  7. }
  8.  
  9. Complex Transformation::Transf(const Complex &G) const
  10. {
  11. if (e)
  12. {
  13. //e=1 nesobstv e=0 sobstv
  14. return (a * Complex::conj(G) + b)/(c * Complex::conj(G) + d);
  15. }
  16. else
  17. {
  18. return (a * G + b)/(c * G + d);
  19. }
  20. }
  21.  
  22. Transformation Transformation::operator *(const Transformation &t) const
  23. {
  24. if(e){
  25. return {
  26. ((a * Complex::conj(t.a)) + (b * Complex::conj(t.c))),
  27. ((a * Complex::conj(t.b)) + (b * Complex::conj(t.d))),
  28. ((c * Complex::conj(t.a)) + (d * Complex::conj(t.c))),
  29. ((c * Complex::conj(t.b)) + (d * Complex::conj(t.d))),
  30. (e != t.e)
  31. };
  32. } else {
  33. return {
  34. ((a * t.a) + (b * t.c)),
  35. ((a * t.b) + (b * t.d)),
  36. ((c * t.a) + (d * t.c)),
  37. ((c * t.b) + (d * t.d)),
  38. (e != t.e)
  39. };
  40. }
  41. }
  42.  
  43. Transformation Transformation::operator ^(const int &k) const
  44. {
  45. int l=k;
  46. Transformation t;
  47. Transformation f={a, b, c, d, e};
  48. Transformation g={d, -b, -c, a, e};
  49. if(k>0){
  50. while(l--){
  51. t=t*f;
  52. }
  53. } else {
  54. while(l++){
  55. t=t*g;
  56. }
  57. }
  58. return t;
  59. }
  60.  
  61. bool Transformation::operator == (const Transformation &t) const
  62. {
  63. if((a==t.a)&&(b==t.b)&&(c==t.c)&&(d==t.d)&&(e==t.e)){
  64. return 0;
  65. } else {
  66. return 1;
  67. }
  68. }
  69.  
  70. bool Transformation::operator != (const Transformation &t) const{
  71. if((a!=t.a)||(b!=t.b)||(c!=t.c)||(d!=t.d)||(e!=t.e)){
  72. return 0;
  73. } else {
  74. return 1;
  75. }
  76. }
  77.  
  78. Transformation Transformation::rotate(const Complex &O, const qreal &ang)
  79. {
  80. Complex g = {qreal(cos(ang)), qreal(sin(ang))};
  81. return {
  82. g,
  83. O - O * g,
  84. {0, 0},
  85. {1, 0},
  86. 0
  87. };
  88. }
  89.  
  90. /*Transformation Transformation::invers(Circle &G)
  91. {
  92. QVector<Complex> F = G.getCenter_and_Radius();
  93. if (F.at(0) == Complex(2,0))
  94. {
  95. QVector<Complex> K=G.equation();
  96. return {
  97. K.at(2)/K.at(0),
  98. -K.at(3)/K.at(0),
  99. Complex(1,0),
  100. -Complex::conj(K.at(2)/K.at(0)),
  101. 1
  102. };
  103. }
  104. else
  105. {
  106. Complex g = G.A - G.B;
  107. return {
  108. g,
  109. G.B * Complex::conj(G.A) - G.A * Complex::conj(G.B),
  110. 0,
  111. Complex::conj(g),
  112. 1
  113. };
  114. }
  115. }*/
  116.  
  117. /*auto fixp()
  118. {
  119. a=initializatoin
  120. if (e){
  121. if(c==Co_Z){
  122.  
  123. } else {
  124.  
  125. }
  126. } else {
  127. if(c==Co_Z){
  128. if(a==Co_1){
  129. return {Co_1/Co_i};
  130. } else {
  131. return {b/(Co_1-a),Co_1/Co_i};
  132. }
  133. } else {
  134.  
  135. }
  136. }
  137. return {a};
  138. }*/
  139.  

pro файл

  1. QT += core gui
  2.  
  3. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  4.  
  5. CONFIG += c++14
  6.  
  7. # The following define makes your compiler emit warnings if you use
  8. # any Qt feature that has been marked deprecated (the exact warnings
  9. # depend on your compiler). Please consult the documentation of the
  10. # deprecated API in order to know how to port your code away from it.
  11. DEFINES += QT_DEPRECATED_WARNINGS
  12.  
  13. # You can also make your code fail to compile if it uses deprecated APIs.
  14. # In order to do so, uncomment the following line.
  15. # You can also select to disable deprecated APIs only up to a certain version of Qt.
  16. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
  17.  
  18. SOURCES += \
  19. circle.cpp \
  20. complex.cpp \
  21. main.cpp \
  22. mainwindow.cpp \
  23. simplemenu.cpp \
  24. transformation.cpp \
  25. view.cpp
  26.  
  27. HEADERS += \
  28. circle.h \
  29. complex.h \
  30. mainwindow.h \
  31. simplemenu.h \
  32. transformation.h \
  33. view.h
  34.  
  35. FORMS += \
  36. mainwindow.ui \
  37. simplemenu.ui
  38.  
  39. # Default rules for deployment.
  40. qnx: target.path = /tmp/$${TARGET}/bin
  41. else: unix:!android: target.path = /opt/$${TARGET}/bin
  42. !isEmpty(target.path): INSTALLS += target
  43.  
2

Вам это нравится? Поделитесь в социальных сетях!

2
G
  • 29 августа 2021 г. 13:30
  • (ред.)

Похоже, ошибка была в pro файле: в 1 строке лишний отступ? (Можете рассказать про синтаксис pro файла?). Пойду проверять работает ли всё

    Evgenii Legotckoi
    • 11 октября 2021 г. 13:14

    Маловероятно, скорее всего нужно было перезапустить qmake после создания файла.

      Комментарии

      Только авторизованные пользователи могут публиковать комментарии.
      Пожалуйста, авторизуйтесь или зарегистрируйтесь