Pages : 1
#1 Le 10/05/2009, à 11:34
- rodjarc
Probleme avec une class (C++)
Bonjour, j'ai crée une class qui regroupe les différente instruction pour demmarer les socket mais je reçoit un message erreur sur le contructeur
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|26|erreur: nouveaux types ne peuvent être définis dans un type à retourner|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|26|note: (perhaps a semicolon is missing after the definition of ‘Client_serveur’)|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|26|erreur: spécification de type retourné pour un constructeur est invalide|
||=== Build finished: 2 errors, 0 warnings ===|
voila mon code
#if defined (WIN32)
#include <winsock2.h>
typedef int socklen_t;
#elif defined (linux)
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define closesocket(s) close(s)
typedef int SOCKET;
typedef struct sockaddr_in SOCKADDR_IN;
typedef struct sockaddr SOCKADDR;
#endif
#include <iostream>
#include <string>
#include "client-serveur.h"
Client_serveur::Client_serveur(void)
{
#if defined (WIN32)
WSADATA WSAData;
erreur = WSAStartup(MAKEWORD(2,2), &WSAData);
#else
erreur=0;
#endif
port =500;
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
stop= true;
}
void Client_serveur::reception ( )
{
if(connect(sock, (SOCKADDR*)&sin, sizeof(sin)) != SOCKET_ERROR)
{
std::cout <<"Connection à "<<inet_ntoa(sin.sin_addr) << " sur le port " <<htons(sin.sin_port)<<std::endl;
/* Si l'on reçoit des informations : on les affiche à l'écran */
while(stop)
{
if(recv(sock, buffer, 32, 0) != SOCKET_ERROR)
std::cout << "Recu : " <<buffer<<std::endl;
}
}
else
{
std::cout << "Impossible de se connecter" <<std::endl;
}
}
void Client_serveur::envoi()
{
}
void Client_serveur::creation_socket()
{
if(!erreur)
{
/* Création de la socket */
sock = socket(AF_INET, SOCK_STREAM, 0);
/* Configuration de la connexion */
sin.sin_addr.s_addr = inet_addr("127.0.0.1");
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
}
}
void Client_serveur::fermetur_socket()
{
/* On ferme la socket */
closesocket(sock);
#if defined (WIN32)
WSACleanup();
#endif
}
#include <iostream>
#include <string>
class Client_serveur
{
SOCKET sock;
int erreur;
SOCKADDR_IN sin;
char buffer[32];
int port;
bool stop;
public:
Client_serveur(void);
void reception ( );
void envoi();
void fermetur_socket();
void creation_socket();
}
que puis-je faire pour corriger se problème ?
//ubuntu 9.10//intel core 2 duo 2.6 GHz//ati radeon//
Hors ligne
#2 Le 10/05/2009, à 11:59
- $Gaël$
Re : Probleme avec une class (C++)
Es-tu sûr que le type bool est connu?
Ubuntu is an ancient african word meaning : "I can't configure Debian".
Hors ligne
#3 Le 10/05/2009, à 12:05
- rodjarc
Re : Probleme avec une class (C++)
Ba le type bool c bien du C++ je confond pas ? en faite le programme marcher avant que je fasse la séparation de prototype.( Quand les 2 fichier ne faisait qu'un ^^ )
//ubuntu 9.10//intel core 2 duo 2.6 GHz//ati radeon//
Hors ligne
#4 Le 10/05/2009, à 12:29
- max edroume
Re : Probleme avec une class (C++)
Dans le .h rajoute un point-virgule après la dernière accolade de la classe
#5 Le 10/05/2009, à 12:33
- rodjarc
Re : Probleme avec une class (C++)
C bon , j'ai plus le message d'errreur, ^^
j'en est de nouveau -_-mais avec le point virgul
obj/Debug/main.o||In function `Client_serveur::envoi()':|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|69|multiple definition of `Client_serveur::envoi()'|
obj/Debug/client-serveur.o:/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|69|first defined here|
obj/Debug/main.o||In function `Client_serveur::fermetur_socket()':|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|89|multiple definition of `Client_serveur::fermetur_socket()'|
obj/Debug/client-serveur.o:/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|89|first defined here|
obj/Debug/main.o||In function `Client_serveur::creation_socket()':|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|74|multiple definition of `Client_serveur::creation_socket()'|
obj/Debug/client-serveur.o:/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|74|first defined here|
obj/Debug/main.o||In function `Client_serveur':|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|26|multiple definition of `Client_serveur::Client_serveur()'|
obj/Debug/client-serveur.o:/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|26|first defined here|
obj/Debug/main.o||In function `Client_serveur':|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|26|multiple definition of `Client_serveur::Client_serveur()'|
obj/Debug/client-serveur.o:/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|26|first defined here|
obj/Debug/main.o||In function `Client_serveur::reception()':|
/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|45|multiple definition of `Client_serveur::reception()'|
obj/Debug/client-serveur.o:/home/rodolphe/Bureau/Projet OPEN GAME/ORRIGINAL/Client/open-game/client-serveur.cpp|45|first defined here|
||=== Build finished: 12 errors, 0 warnings ===|
Dernière modification par rodjarc (Le 10/05/2009, à 12:39)
//ubuntu 9.10//intel core 2 duo 2.6 GHz//ati radeon//
Hors ligne
#6 Le 10/05/2009, à 12:50
- max edroume
Re : Probleme avec une class (C++)
Dans le .h met une barrière qui empêche les inclusions multiples:
#ifndef CLIENT_SERVEUR_H
#define CLIENT_SERVEUR_H
( ancien contenu du .h )
#endif
#7 Le 10/05/2009, à 12:57
- rodjarc
Re : Probleme avec une class (C++)
Sa a rien changer
//ubuntu 9.10//intel core 2 duo 2.6 GHz//ati radeon//
Hors ligne
#8 Le 10/05/2009, à 13:09
- max edroume
Re : Probleme avec une class (C++)
ça aurait dû
Bon courage..
#9 Le 10/05/2009, à 19:31
- Le Farfadet Spatial
Re : Probleme avec une class (C++)
Salut à tous !
Sa a rien changer
Poste ton code tel qu'il est maintenant : je pense avoir une idée, mais il faut que je vois ton code pour m'en assurer (et ce sera plus facile à expliquer).
À bientôt.
Le Farfadet Spatial
Hors ligne
Pages : 1