G
Gintoki-_-28 августа 2021 г. 14:11

Ошибка undefined reference to

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

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

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

Ошибки

complex.h

#ifndef COMPLEX_H
#define COMPLEX_H

#include <QtMath>

class Complex
{
    public:
        qreal real;
        qreal imag;
        bool inf;

        Complex(const qreal &a=0, const qreal &b=0, const bool &c=1);

        /*Complex(const Complex &a);

        Complex operator = (const Complex &a);*/

        //~Complex();

        static qreal norm (const Complex &a);

        static qreal abs (const Complex &a);

        static qreal arg (const Complex &a);

        static Complex conj (const Complex &a);

        Complex operator - () const;

        Complex operator + (const Complex &a) const;

        Complex operator - (const Complex &a) const;

        Complex operator * (const Complex &a) const;

        Complex operator / (const Complex &a) const;

        bool operator == (const Complex &a) const;

        bool operator != (const Complex &a) const;

        static Complex exp(const Complex &a);

        static Complex ln(const Complex &a);

        static Complex pow (const Complex &a, const Complex &b);

        static Complex sin(const Complex &a);

        static Complex cos(const Complex &a);

};

#endif

transformation.h

#ifndef TRANSFORMATION_H
#define TRANSFORMATION_H

#include "complex.h"
#include <QVector>
//#include "circle.h"

class Transformation
{
  private:
    Complex a;
    Complex b;
    Complex c;
    Complex d;
    bool e;

  public:

    //конструктор
    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);

    Complex Transf(const Complex &G) const;

    //оператор композиции (последовательное применение)
    Transformation operator *(const Transformation &t) const;

    //оператор итерации (последовательное примение одного преобразования несколько раз)
    Transformation operator ^(const int &k) const;

    //оператор сравнения, возвращает true если преобразования одинаковы
    bool operator == (const Transformation &t) const;

    //оператор сравнения, возвращает true если преобразования различны
    bool operator != (const Transformation &t) const;

    //поворот(центр поворота, угол)
    static Transformation rotate(const Complex &O, const qreal &ang);

    //static Transformation invers(Circle &G);

};


#endif // TRANSFORMATION_H

complex.cpp

#include "complex.h"

Complex::Complex(const qreal &a, const qreal &b, const bool &c)
    : real{a}, imag{b}, inf{c}
{

}

/*Complex::Complex(const Complex &a)
    : real{a.real}, imag{a.imag}, inf{a.inf}
{

}

Complex Complex::operator =(const Complex &a)
{
    real = a.real;
    imag = a.imag;
    inf = a.inf;
    return {a.real, a.imag, a.inf};
}
*/

/*Complex::~Complex(){
    delete real, imag, inf;
}*/

/*
{
    if (a.inf)
    {
        out << a.real;
        if (a.imag==0){
            out << "+0i";
        } else {
            if (a.imag > 0)
            {
                out << "+";
            }
            out << a.imag << "i";
        }
    }
    else
    {
        out << "∞";
    }
    return out;
}*/

qreal Complex::norm(const Complex &a)
{
    return a.real * a.real + a.imag * a.imag;
}

qreal Complex::abs(const Complex &a)
{
    return qSqrt(Complex::norm(a));
}

qreal Complex::arg(const Complex &a)
{
    if (a.real == 0)
    {
        return ((a.real > 0) - (a.real < 0)) * qAcos(-1) / 2;
    }
    else if ((a.real < 0) && (a.imag > 0))
    {
        return qAcos(-1) + qAtan(a.imag / a.real);
    }
    else
    {
        return -qAcos(-1) + qAtan(a.imag / a.real);
    }
}

Complex Complex::conj(const Complex &a)
{
    return {a.real, -a.imag, a.inf};
}

Complex Complex::operator -() const
{
    if (inf)
    {
        return {-real,-imag};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator+(const Complex &a) const
{
    if ((inf) && (a.inf))
    {
        return {real + a.real, imag + a.imag};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator-(const Complex &a) const
{
    if ((inf) && (a.inf))
    {
        return {real - a.real, imag - a.imag};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator*(const Complex &a) const
{
    if ((inf) && (a.inf))
    {
        return {real * a.real - imag * a.imag, real * a.imag + imag * a.real};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::operator/(const Complex &a) const
{
    Complex out;
    if ((inf) && (a.inf))
    {
        if ((a.real == 0) && (a.imag == 0))
        {
            out={0, 0, 0};
        }
        else
        {
            Complex d = *this;
            Complex r = d * Complex::conj(a);
            out = {r.real / Complex::norm(a), r.imag / Complex::norm(a)};
        }
    }
    else if (inf)
    {
        out = {0, 0, 1};
    }

    return out;
}

bool Complex::operator==(const Complex &a) const
{
    if ((real == a.real) && (imag == a.imag) && (inf == a.inf))
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool Complex::operator!=(const Complex &a) const
{
    if ((real - a.real != 0) || (imag - a.imag != 0) || (inf - a.inf != 0))
    {
        return true;
    }
    else
    {
        return false;
    }
}

Complex Complex::exp(const Complex &a)
{
    if (a.inf)
    {
        return {qExp(a.real) * qCos(a.imag), qExp(a.real) * qSin(a.imag)};
    }
    else
    {
        return {0, 0, 0};
    }
}

Complex Complex::ln(const Complex &a)
{
    if ((a.real==0)&&(a.imag==0))
    {
        return {0,0,0};
    }
    else
    {
        return {qLn(Complex::abs(a)), qAcos(a.real / Complex::abs(a))};
    }
}

Complex Complex::pow(const Complex &a, const Complex &b)
{
    return (Complex::exp(Complex::ln(a) * b));
}

Complex Complex::sin(const Complex &a)
{
    return (Complex::exp(Complex(0, 1) * a) - Complex::exp(Complex(0, -1) * a)) / Complex(0, 2);
}

Complex Complex::cos(const Complex &a)
{
    return (Complex::exp(Complex(0, 1) * a) + Complex::exp(Complex(0, -1) * a)) / Complex(2, 0);
}

transformation.cpp

#include "transformation.h"

Transformation::Transformation(const Complex &a_1, const Complex &b_1, const Complex &c_1, const Complex &d_1, const bool &e_1)
    : a{a_1}, b{b_1}, c{c_1}, d{d_1}, e{e_1}
{

}

Complex Transformation::Transf(const Complex &G) const
{
    if (e)
    {
        //e=1 nesobstv e=0 sobstv
        return (a * Complex::conj(G) + b)/(c * Complex::conj(G) + d);
    }
    else
    {
        return (a * G + b)/(c * G + d);
    }
}

Transformation Transformation::operator *(const Transformation &t) const
{
    if(e){
        return {
            ((a * Complex::conj(t.a)) + (b * Complex::conj(t.c))),
            ((a * Complex::conj(t.b)) + (b * Complex::conj(t.d))),
            ((c * Complex::conj(t.a)) + (d * Complex::conj(t.c))),
            ((c * Complex::conj(t.b)) + (d * Complex::conj(t.d))),
            (e != t.e)
        };
    } else {
        return {
            ((a * t.a) + (b * t.c)),
            ((a * t.b) + (b * t.d)),
            ((c * t.a) + (d * t.c)),
            ((c * t.b) + (d * t.d)),
            (e != t.e)
        };
    }
}

Transformation Transformation::operator ^(const int &k) const
{
    int l=k;
    Transformation t;
    Transformation f={a, b, c, d, e};
    Transformation g={d, -b, -c, a, e};
    if(k>0){
        while(l--){
            t=t*f;
        }
    } else {
        while(l++){
            t=t*g;
        }
    }
    return t;
}

bool Transformation::operator == (const Transformation &t) const
{
    if((a==t.a)&&(b==t.b)&&(c==t.c)&&(d==t.d)&&(e==t.e)){
        return 0;
    } else {
        return 1;
    }
}

bool Transformation::operator != (const Transformation &t) const{
    if((a!=t.a)||(b!=t.b)||(c!=t.c)||(d!=t.d)||(e!=t.e)){
        return 0;
    } else {
        return 1;
    }
}

Transformation Transformation::rotate(const Complex &O, const qreal &ang)
{
    Complex g = {qreal(cos(ang)), qreal(sin(ang))};
    return {
            g,
            O - O * g,
            {0, 0},
            {1, 0},
            0
            };
}

/*Transformation Transformation::invers(Circle &G)
{
    QVector<Complex> F = G.getCenter_and_Radius();
    if (F.at(0) == Complex(2,0))
    {
        QVector<Complex> K=G.equation();
        return {
            K.at(2)/K.at(0),
            -K.at(3)/K.at(0),
            Complex(1,0),
            -Complex::conj(K.at(2)/K.at(0)),
            1
        };
    }
    else
    {
        Complex g = G.A - G.B;
        return {
            g,
            G.B * Complex::conj(G.A) - G.A * Complex::conj(G.B),
            0,
            Complex::conj(g),
            1
            };
    }
}*/

/*auto fixp()
{
        a=initializatoin
        if (e){
            if(c==Co_Z){

            } else {

            }
        } else {
            if(c==Co_Z){
                if(a==Co_1){
                    return {Co_1/Co_i};
                } else {
                    return {b/(Co_1-a),Co_1/Co_i};
                }
            } else {

            }
        }
    return {a};
}*/

pro файл

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++14

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    circle.cpp \
    complex.cpp \
    main.cpp \
    mainwindow.cpp \
    simplemenu.cpp \
    transformation.cpp \
    view.cpp

HEADERS += \
    circle.h \
    complex.h \
    mainwindow.h \
    simplemenu.h \
    transformation.h \
    view.h

FORMS += \
    mainwindow.ui \
    simplemenu.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

Рекомендуем хостинг TIMEWEB
Рекомендуем хостинг TIMEWEB
Стабильный хостинг, на котором располагается социальная сеть EVILEG. Для проектов на Django рекомендуем VDS хостинг.

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

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

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

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

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

      Комментарии

      Только авторизованные пользователи могут публиковать комментарии.
      Пожалуйста, авторизуйтесь или зарегистрируйтесь
      e
      • ehot
      • 1 апреля 2024 г. 0:29

      C++ - Тест 003. Условия и циклы

      • Результат:78баллов,
      • Очки рейтинга2
      B

      C++ - Тест 002. Константы

      • Результат:16баллов,
      • Очки рейтинга-10
      B

      C++ - Тест 001. Первая программа и типы данных

      • Результат:46баллов,
      • Очки рейтинга-6
      Последние комментарии
      k
      kmssr9 февраля 2024 г. 5:43
      Qt Linux - Урок 001. Автозапуск Qt приложения под Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
      АК
      Анатолий Кононенко5 февраля 2024 г. 12:50
      Qt WinAPI - Урок 007. Работаем с ICMP Ping в Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
      EVA
      EVA25 декабря 2023 г. 21:30
      Boost - статическая линковка в CMake проекте под Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
      J
      JonnyJo25 декабря 2023 г. 19:38
      Boost - статическая линковка в CMake проекте под Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
      G
      Gvozdik19 декабря 2023 г. 8:01
      Qt/C++ - Урок 056. Подключение библиотеки Boost в Qt для компиляторов MinGW и MSVC Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
      Сейчас обсуждают на форуме
      a
      a_vlasov14 апреля 2024 г. 16:41
      Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
      Павел Дорофеев
      Павел Дорофеев14 апреля 2024 г. 12:35
      QTableWidget с 2 заголовками Вот тут есть кастомный QTableView с многорядностью проект поддерживается, обращайтесь
      f
      fastrex4 апреля 2024 г. 14:47
      Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…
      P
      Pisych27 февраля 2023 г. 15:04
      Как получить в массив значения из связанной модели? Спасибо, разобрался:))
      AC
      Alexandru Codreanu19 января 2024 г. 22:57
      QML Обнулить значения SpinBox Доброго времени суток, не могу разобраться с обнулением значение SpinBox находящего в делегате. import QtQuickimport QtQuick.ControlsWindow { width: 640 height: 480 visible: tr…

      Следите за нами в социальных сетях