Не могу вызвать методы set_connect и emit_signal

У меня вопрос по учебной задаче (сигналы и слоты), не получается вызвать методы set_connect и emit_signal в классе root, помогите пожалуйста и также я не уверен, правильно ли я написал вызов в методе emit_signal класса cl_base. Ниже прикреплю весь код. Заранее спасибо.

https://ibb.co/Tr8LBzw - ошибки при сборке

неправильно написаны вызовы в файле cl_root.cpp строчки from->set_connect(SIGNAL_D(from->signal), to, HENDLER_D(to->handler)); и run->emit_signal(SIGNAL_D(run->signal), slovo); Буду очень благодарен за помощь, вообще не понимаю, что не так

ошибки при сборке:

In file included from C:\Users\micron\source\CLion\stack_overflow\cl_1.h:7,
                 from C:\Users\micron\source\CLion\stack_overflow\cl_root.cpp:8:
C:\Users\micron\source\CLion\stack_overflow\cl_root.cpp: In member function 'void cl_root::set_all()':
C:\Users\micron\source\CLion\stack_overflow\cl_root.cpp:68:46: error: 'class cl_base' has no member named 'signal'
   68 |             from->set_connect(SIGNAL_D(from->signal), to, HENDLER_D(to->handler));
      |                                              ^~~~~~
C:\Users\micron\source\CLion\stack_overflow\cl_base.h:7:44: note: in definition of macro 'SIGNAL_D'
    7 | #define SIGNAL_D(signal_f) (TYPE_SIGNAL) (&signal_f))
      |                                            ^~~~~~~~
C:\Users\micron\source\CLion\stack_overflow\cl_root.cpp:68:73: error: 'class cl_base' has no member named 'handler'
   68 |             from->set_connect(SIGNAL_D(from->signal), to, HENDLER_D(to->handler));
      |                                                                         ^~~~~~~
C:\Users\micron\source\CLion\stack_overflow\cl_base.h:8:47: note: in definition of macro 'HENDLER_D'
    8 | #define HENDLER_D(hendler_f) (TYPE_HANDLER) (&hendler_f))
      |                                               ^~~~~~~~~
C:\Users\micron\source\CLion\stack_overflow\cl_root.cpp: In member function 'int cl_root::exec_app()':
C:\Users\micron\source\CLion\stack_overflow\cl_root.cpp:92:44: error: 'class cl_base' has no member named 'signal'
   92 |             run->emit_signal(SIGNAL_D(run->signal), slovo);
      |                                            ^~~~~~
C:\Users\micron\source\CLion\stack_overflow\cl_base.h:7:44: note: in definition of macro 'SIGNAL_D'
    7 | #define SIGNAL_D(signal_f) (TYPE_SIGNAL) (&signal_f))

main.cpp

#include "cl_base.h"
#include "cl_root.h"
int main(){
    cl_root ob_root(NULL);
    ob_root.set_all();
    return ob_root.exec_app();
} 

cl_base.h

#ifndef CL_BASE_H
#define CL_BASE_H
#define SIGNAL_D(signal_f) (TYPE_SIGNAL) (&signal_f))
#define HENDLER_D(hendler_f) (TYPE_HANDLER) (&hendler_f))
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class cl_base{
protected:
    string name;
    cl_base* p_parent;
    int number;
    int readiness;
    vector <cl_base*> children;
    vector <string> m_coordinates;
    vector <string> links;
    typedef void (cl_base::* TYPE_SIGNAL) (string&);
    typedef void (cl_base::* TYPE_HANDLER) (string);
    struct o_sh{
        TYPE_SIGNAL p_signal;
        cl_base* p_cl_base;
        TYPE_HANDLER p_hendler;
    };
    vector <o_sh*> connects;
    vector <o_sh*>::iterator it;

public:
    cl_base(cl_base* p_parent);
    cl_base(cl_base* p_parent, string name, int number, int readiness);
    string get_object_name();
    ~cl_base();
    cl_base* search(string coordinates);
    bool test_for_uniqueness();
    void readiness_check();
    void showtree(int counter);
    cl_base* search_coordinates(string coordinates);
    void set_connect(TYPE_SIGNAL p_signal, cl_base* p_object, TYPE_HANDLER p_ob_hendler);
    void delete_connect(TYPE_SIGNAL p_signal, cl_base* p_object, TYPE_HANDLER p_ob_hendler);
    void emit_signal(TYPE_SIGNAL p_signal, string & s_command);
};

#endif

cl_base.cpp

#include <iostream>
#include <string>
#include <vector>
#include "cl_base.h"
#include "cl_root.h"
#include "cl_1.h"
#include "cl_2.h"
#include "cl_3.h"
using namespace std;

cl_base::cl_base(cl_base* p_parent){
    this->p_parent = p_parent;
    if (p_parent != 0)
    {
        this->p_parent->children.push_back(this);
    }
}

cl_base::cl_base(cl_base* p_parent, string name, int number, int readiness){
    this->name = name;
    this->p_parent = p_parent;
    if (p_parent != 0)
    {
        this->p_parent->children.push_back(this);
    }
    this->number = number;
    this->readiness = readiness;
}

string cl_base::get_object_name(){
    return this->name;
}

cl_base::~cl_base(){
    for (int i = 0; i < this->children.size(); i++)
        delete this->children[i];
}

cl_base* cl_base::search(string name){
    if (this->name == name){
        return this;
    }
    for (int i = 0; i < this->children.size(); i++){
        if (this->children[i]->name == name)
        {
            return this->children[i];
        }
    }
    for (int i = 0; i < this->children.size(); i++){
        if (this->children[i]->children.size() != 0)
        {
            cl_base* pointer = children[i]->search(name);
            if (pointer != nullptr)
                return pointer;
        }
    }
    return nullptr;
}

bool cl_base::test_for_uniqueness(){
    for (int i = 0; i < this->children.size(); i++)
    {
        if (this->children[i]->name == this->name)
            return false;
        if (this->children[i]->children.size() != 0)
            children[i]->test_for_uniqueness();
    }
    return true;
}

void cl_base::readiness_check(){
    if (this->number == 1)
        cout << "Test result";
    if ((this->search(this->name) != nullptr) && (this->readiness > 0) && (this->test_for_uniqueness() == true))
    {
        cout << endl << "The object " << this->name << " is ready";
    }
    else
    {
        cout << endl << "The object " << this->name << " is not ready";
    }
    for (int i = 0; i < this->children.size(); i++)
    {
        children[i]->readiness_check();
    }
}

void cl_base::showtree(int counter){
    if (this->number == 1)
        cout << "Object tree";
    cout << endl;
    for (int i = 0; i < counter; i++)
        cout << "    ";
    counter++;
    cout << this->name;
    for (int i = 0; i < this->children.size(); i++)
    {
        this->children[i]->showtree(counter);
    }
}

cl_base* cl_base::search_coordinates(string coordinates){
    string m_coordinates;
    coordinates.erase(0, 1);
    int number = coordinates.find('/');
    if (number == -1)
    {
        m_coordinates = coordinates;
        coordinates.erase(0, coordinates.size());
    }
    else
    {
        for (int i = 0; i < number; i++)
            m_coordinates.push_back(coordinates[i]);
        coordinates.erase(0, number);
    }
    if (this->name == m_coordinates)
    {
        if (coordinates.size() == 0)
            return this;
        for (int i = 0; i < this->children.size(); i++)
        {
            cl_base* pointer = this->children[i]->search_coordinates(coordinates);
            if (pointer != nullptr)
                return pointer;
        }
    }
    return nullptr;
}

void cl_base::set_connect(TYPE_SIGNAL p_signal, cl_base* p_object, TYPE_HANDLER p_ob_hendler){
    o_sh* p_value;
    for (unsigned int i = 0; i < connects.size(); i++)
    {
        if (connects[i]->p_signal == p_signal && connects[i]->p_cl_base == p_object && connects[i]->p_hendler == p_ob_hendler)
            return;
    }
    p_value = new o_sh();
    p_value->p_signal = p_signal;
    p_value->p_cl_base = p_object;
    p_value->p_hendler = p_ob_hendler;
    connects.push_back(p_value);
}

void cl_base::delete_connect(TYPE_SIGNAL p_signal, cl_base* p_object, TYPE_HANDLER p_ob_hendler){
    if (connects.empty())
        return;
    for (unsigned int i = 0; i < connects.size(); i++)
    {
        if (connects[i]->p_signal == p_signal && connects[i]->p_cl_base == p_object && connects[i]->p_hendler == p_ob_hendler)
            connects.erase(connects.begin() + i);
    }
}

void cl_base::emit_signal(TYPE_SIGNAL p_signal, string& s_command){
    if (connects.empty())
        return;
    string forename = this->get_object_name();
    it = connects.begin();
    for (it; it != connects.end(); it++)
    {
        if ((*(it))->p_signal == p_signal)
        {
            cout << endl;
            (this->*((*(it))->p_signal))(s_command);
            (((*(it))->p_cl_base)->*((*(it))->p_hendler))(s_command);
            cout << forename << " -> " << s_command;
        }
    }
}

cl_root.h

#ifndef CL_ROOT_H
#define CL_ROOT_H
#include <string>
#include "cl_base.h"
using namespace std;

class cl_root : public cl_base
{
private:
    cl_base* pointer_of_root = NULL;
public:
    using cl_base::cl_base;
    void signal(string& a);
    void handler(string a);
    void set_all();
    int exec_app();
};

#endif

cl_root.cpp

#include <iostream>
#include <string>
#include <vector>
#include "cl_1.h"
#include "cl_2.h"
#include "cl_3.h"
#include "cl_root.h"
using namespace std;

void cl_root::signal(string& a){
    cout << "Signal to " << a;
}

void cl_root::handler(string a){
    cout << " Text: ";
    return;
}

void cl_root::set_all(){
    string name, parent = " ", coordinates;
    int number, readiness;
    cin >> name;
    cl_base* ob_root = new cl_base(0, name, 1, 1);
    pointer_of_root = ob_root;
    while (parent != "endtree")
    {
        cin >> parent;
        if (parent == "endtree")
            break;
        cin >> name >> number >> readiness;
        cl_base* dad = pointer_of_root->search(parent);
        switch (number)
        {
        case 1:
        {
            cl_base* ob_1 = new cl_1(dad, name, number, readiness);
            break;
        }
        case 2:
        {
            cl_base* ob_2 = new cl_2(dad, name, number, readiness);
            break;
        }
        case 3:
        {
            cl_base* ob_3 = new cl_3(dad, name, number, readiness);
            break;
        }
        }
    }
    string number1; string first, second;
    cl_base* from = nullptr;
    cl_base* to = nullptr;
    cin >> number1;
    while (number1 != "0"){
        cin >> first >> second;
        links.push_back(number1);
        links.push_back(first);
        links.push_back(second);
        from = pointer_of_root->search(first);
        to = pointer_of_root->search(second);
        if (from != nullptr)
        {
            from->set_connect(SIGNAL_D(from->signal), to, HENDLER_D(to->handler));
        }
        cin >> number1;
    }
}

int cl_root::exec_app(){
    pointer_of_root->showtree(0);
    cout << endl << "Set connects";
    for (int i = 0; i < links.size(); i+=3)
    {
        cout << endl;
        cout << links[i] << " " << links[i+1] << " " << links[i+2];
    }
    cout << endl << "Emit signals";
    cl_base* run = new cl_base(0);
    string slovo, obj;
    cin >> obj;
    while (obj != "endsignals")
    {
        cin >> slovo;
        run = pointer_of_root->search(obj);
        if (run != nullptr)
        {
            run->emit_signal(SIGNAL_D(run->signal), slovo);
        }
        cin >> obj;
    }
    return 0;
}

cl_1.h

#ifndef CL_1_H
#define CL_1_H
#include "cl_base.h"

class cl_1 : public cl_base{
public:
    using cl_base::cl_base;
    void signal(string& a);
    void handler(string a);
};

#endif

cl_1.cpp

#include <iostream>
#include <string>
#include "cl_1.h"

void cl_1::signal(string& a)
{
    cout << "Signal to " << a;
}
void cl_1::handler(string a)
{
    cout << " Text: ";
    return;
}

cl_2.h

#ifndef CL_2_H
#define CL_2_H
#include "cl_base.h"

class cl_2 : public cl_base
{
public:
    using cl_base::cl_base;
    void signal(string& a);
    void handler(string a);
};

#endif

cl_2.cpp

#include <iostream>
#include <string>
#include "cl_2.h"

void cl_2::signal(string& a)
{
    cout << "Signal to " << a;
}
void cl_2::handler(string a)
{
    cout << " Text: ";
    return;
}

cl_3.h

 #ifndef CL_3_H
#define CL_3_H
#include "cl_base.h"

class cl_3 : public cl_base
{
public:
    using cl_base::cl_base;
    void signal(string& a);
    void handler(string a);
};

#endif

cl_3.cpp

#include <iostream>
#include <string>
#include "cl_3.h"

void cl_3::signal(string& a)
{
    cout << "Signal to " << a;
}
void cl_3::handler(string a)
{
    cout << " Text: ";
    return;
}

https://ibb.co/Tr8LBzw - ошибки при сборке


Ответы (0 шт):