Jump to content

I am writing an UDP chat on c++ using object and the compiler give me this error:

C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.9.2\include\c++\functional|1665|error: no type named 'type' in 'class std::result_of<std::_Mem_fn<void (chat_function::*)()>()>'|

I call the thread only on this main:

#include "chat_function.hpp"
#include "UDP_function.hpp"
#include "config.hpp"
#include <cstring>
#include <stdio.h>
#include <iostream>
#include <thread>
#include <windows.h>

using namespace std;

int main()
{
    chat_function CHAT;

    UDP_function UDP;

    char buffer[BUFF_DIM];
    char buffer1[BUFF_DIM];
    char ip_to_send[]= IP_ADDR_DEST;
    unsigned long ip_address= 0;
    unsigned short port_number= UDP_PORT_SERVER;
    char nome[15];
    int op= 0;
    int error= 0;
    //thread receaving_thread;

    CHAT.Pulizia(buffer, 0, CHAT.cont_buffer(buffer));

    UDP.UDP_init(UDP_PORT_SERVER);

    while(1)
    {
        CHAT.Pulizia(buffer, 0, CHAT.cont_buffer(buffer));
        CHAT.creapacchetto(buffer, nome, op);
        strcpy(ip_to_send, IP_ADDR_DEST);

        // SENDER
        if (error= UDP.UDP_send(UDP.IP_to_bin(ip_to_send), UDP_PORT_SERVER, buffer, sizeof(buffer)))
        {
            cout << "Errore: " << error << endl;
        }
        else
            cout << "Messaggio inviato: \"" << buffer << "\""  << endl;

        if(op== 0)
        {
            CHAT.Pulizia(buffer1, 0, CHAT.cont_buffer(buffer1));

            if (error= UDP.UDP_receive( &ip_address, &port_number, buffer1, sizeof(buffer1)))
            {
                cout << "Errore: " << error << endl;
            }

            if(strcmp(buffer1, WrongPass)== 0)
            {
                op= 0;
                cout << "Password Errata" << endl;
            }

            if(strcmp(buffer1, CorrPass)== 0)
            {
                op= 1;
                cout << "Password Corretta" << endl;

                thread receaving_thread(CHAT.ricezione_messaggi);
            }

            CHAT.Pulizia(buffer1, 0, CHAT.cont_buffer(buffer1));
        }
    }

    UDP.UDP_close();

    return 0;
}

what can i do to solve?

Link to comment
https://linustechtips.com/topic/1319762-multithreading-error-on-codeblock/
Share on other sites

Link to post
Share on other sites

5 hours ago, gabrielcarvfer said:

There's something wrong in the "chat_function" definition. Is it really a function or an instance/object of a class? 

 

No type named 'type' seems like a template error.

chat_function is a class.

declaration:

#ifndef CHAT_FUNCTIONS_H
#define CHAT_FUNCTIONS_H
#include "config.hpp"
#include "UDP_function.hpp"

class chat_function
{
    public:
    //ARGOMENTI
        UDP_function udp;

    //METODI
        void ricezione_messaggi();
        void Pulizia(char vettore[], int dimnecessaria, int dimreale);
        int cont_buffer(char buffer[]);
        void buff_out(char buffer[]);
        void creapacchetto(char buffer[], char nome[15], int op);
        void Copia(char vettdest[], char vettmitt[], int dim_vett);
};

//void ricezione_messaggi();
#endif // CHAT_FUNCTIONS_H

metods:

#include "chat_function.hpp"
#include "UDP_function.hpp"
#include "config.hpp"
#include <iostream>

using namespace std;

//ricezione dei messaggi con rispettiva formattazione
void chat_function::ricezione_messaggi()
//void ricezione_messaggi()
{
    char buffer[BUFF_DIM];
    int error= 0;
    unsigned long ip_address= 0;
    unsigned short port_number= UDP_PORT_HOST;

    Pulizia(buffer, 0, cont_buffer(buffer));

    if (error= udp.UDP_receive(&ip_address, &port_number, buffer, sizeof(buffer)))
    {
        cout << "Errore: " << error << endl;
    }
    else
        buff_out(buffer);

    Pulizia(buffer, 0, cont_buffer(buffer));
}

//pulizia dei buffer
void chat_function::Pulizia(char vettore[], int dimnecessaria, int dimreale)
{
    for(int i=dimnecessaria-1; i<dimreale; i++)
        vettore[i]=0;
}

//contatore dei caratteri di un buffer
int chat_function::cont_buffer(char buffer[])
{
    int i= 0;

    while(buffer[i]!= '\0')
        i++;

    return i;
}

//formattazione dei messaggi ricevuti
void chat_function::buff_out(char buffer[])
{
    int i;

    cout << "<";

    for(i= 1; i< 16; i++)
    {
        if(buffer[i]== 32)
            break;

        cout << buffer[i];
    }

    cout << "> ";

    for(i= 17; i< cont_buffer(buffer); i++)
    {
        cout << buffer[i];
    }
}

//creazione del pacchetto da inviare
void chat_function::creapacchetto(char buffer[], char nome[15], int op)
{
    char password[15];
    char messaggio[MESS_DIM];
    char nome1[15];

    if(op== 0)
    {
        cout << "Inserisci nome: ";
        cin >> nome;
        cout << "Inserisci password: ";
        cin >> password;

        while(strlen(nome)< 15)
            strcat(nome," ");

        strcat(buffer,"$");
        strcat(buffer,nome);
        strcat(buffer,"0");
        strcat(buffer,password);
        strcat(buffer,"\r\n");
    }
    else if(op== 1)
    {
        Copia(nome1, nome, 15);
        Pulizia(nome1, 15, strlen(nome1));

        cout << "Inserisci messaggio: ";
        cin.ignore();
        cin.getline(messaggio, 400);

        strcat(buffer, "$");
        strcat(buffer,nome1);
        strcat(buffer,"1");
        strcat(buffer,messaggio);
        strcat(buffer,"\r\n");
    }
}

//copia dei valori di un buffer in un altro
void chat_function::Copia(char vettdest[], char vettmitt[], int dim_vett)
{
    for(int i=0; i<dim_vett; i++)
        vettdest[i]=vettmitt[i];
}

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×