-1

When I tried to compile my game; and it says like

Networking/Sockets/Socket.hpp:18:81: error: expected identifier before ')' token

so if you want to see the source code I've in github here the link: https://github.com/suky637/ServerPlusPlus for peaple that do not want to go to github I will send you the Socket.hpp (this is the main error source) the code:

#ifndef Socket_hpp
#define Socket_hpp

#include <stdio.h>
#include <WinSock2.h>
#include <winsock.h>
#include <iostream>

namespace spp
{
class Socket {
    private:
        struct sockaddr_in address;        
        int sock;
        int connection;
    public: 
        // Constructor
        Socket(int domain, int service, int protocol, int port, u_long interface_parameter);
        // Virtual function to confirm to connect to the network
        virtual int connect_to_network(int sock, struct sockaddr_in address) = 0;
        // Function to test sockets and connection
        void test_connection(int);
        // Getter function
        struct sockaddr_in get_address();
        int get_sock();
        int get_connection();

            // Setter function
        void set_connection(int connection_);
        
};
}

#endif

oh and this is the output:

// command : g++ Server.cpp -o ServerPlusPlus
In file included from Networking/Sockets/_ServerPlusPlus-sockets.hpp:6:0,
                 from Networking/ServerPlusPlus-Networking.hpp:6,
                 from ServerPlusPlus.hpp:6,
                 from Server.cpp:1:
Networking/Sockets/Socket.hpp:19:81: error: expected identifier before ')' token

Socket.cpp

#include "Socket.hpp"

// Default constructor

spp::Socket::Socket(int domain, 
int service, 
int protocol, 
int port,u_long interface_parameter,
)
{
    // Define address structure
    address.sin_family = domain;
    address.sin_port = port;
    address.sin_addr.s_addr = htonl(interface_parameter);
    // Establish socket
    sock = socket(domain,service,protocol);
    test_connection(sock);
    // Establish Connection
    connection = connect_to_network(sock, address);
    test_connection(connect_to_network);
}

// Test Connection virtual function

void spp::Socket::test_connection(int item_to_test)
{
    // Comfirm that the socket or connection has bin properly established
    if (item_to_test < 0)
    {
        perror("Failed To Connect...");
        exit(EXIT_FAILURE);
    }
}

// Getter functions

struct sockaddr_in spp::Socket::get_address()
{
    return address;
}

int spp::Socket::get_sock()
{
    return sock;
}

int spp::Socket::get_connection()
{
    return connection;
}

// Setter functions
void spp::Socket::set_connection(int connection_)
{
    connection = connection_;
}

the main funtion where I compile is

#include "ServerPlusPlus.hpp"

using namespace std;

int main()
{
    cout << "*--------- Starting ---------*" << endl;
    cout << "* Binding Socket... ";
    spp::BindingSocket bs = spp::BindingSocket(AF_INET,SOCK_STREAM,0,80,INADDR_ANY);
    cout << "Complete\n* Listening Socket... ";
    spp::ListeningSocket ls = spp::ListeningSocket(AF_INET, SOCK_STREAM, 0, 80, INADDR_ANY, 10);
    cout << "Complete\n\n\n* Sucess!" << endl;
    system("pause");
}

probably it is the file I copile and ServerPlusPlus.hpp is

#ifndef ServerPlusPlus
#define ServerPlusPlus

#include <stdio.h>

#include "Networking/ServerPlusPlus-Networking.hpp"

#endif

and ServerPlusPlus-Networking.hpp

#ifndef ServerPlusPlus_Networking_hpp
#define ServerPlusPlus_Networking_hpp

#include <stdio.h>

#include "Sockets/_ServerPlusPlus-sockets.hpp"

#endif

and ServerPlusPlus_Sockets_hpp

#ifndef ServerPlusPlus_Sockets_hpp
#define ServerPlusPlus_Sockets_hpp

#include <stdio.h>

#include "Socket.hpp"

#include "BindingSocket.hpp"
#include "ListeningSocket.hpp"

#include "ConnectingSocket.hpp"

#endif

1 Answers1

1

You seem to have missed that actual answer.

interface is used as a typedef in some windows headers

see What is the "interface" keyword in MSVC?

change the name to iface or something like that

pm100
  • 48,078
  • 23
  • 82
  • 145
  • I changed it and it does nothing – Suky Laplante Feb 03 '22 at 23:14
  • I changed to iface and nothing change but I think it is the main file – Suky Laplante Feb 03 '22 at 23:15
  • Wait I think I've miss all the files – Suky Laplante Feb 03 '22 at 23:16
  • Now it C:\Users\sukyl\AppData\Local\Temp\ccQSfExe.o:Server.cpp:(.text+0x7c): undefined reference to `spp::BindingSocket::BindingSocket(int, int, int, int, unsigned long)' C:\Users\sukyl\AppData\Local\Temp\ccQSfExe.o:Server.cpp:(.text+0xcc): undefined reference to `spp::ListeningSocket::ListeningSocket(int, int, int, int, unsigned long, int)' collect2.exe: error: ld returned 1 exit status – Suky Laplante Feb 03 '22 at 23:19
  • thx you just remove the most of the error and the other most is syntaxes error – Suky Laplante Feb 03 '22 at 23:24