simple problem, please help
ok i have not coded in c++ for nearly a year now, and i have forgotten quite a bit and i can't remember how to solve a problem
i get the following error code
C:\Documents and Settings\chris285\Desktop\client\connect.cpp(64) : error C2661: 'connect::connect' : no overloaded function takes 3 parameters
on this piece of code
Code:
// connect.cpp: implementation of the connect class.
//
//////////////////////////////////////////////////////////////////////
#include "connect.h"
#include <winsock2.h>
#include <stdio.h>
#include <iostream>
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
connect::connect()
{
}
connect::~connect()
{
}
int connect::startclient(unsigned short port, const char *serverName)
{
int error;
WSAData wsaData; // the winsock data structure
if ((error = WSAStartup(MAKEWORD(2, 2), &wsaData)) == SOCKET_ERROR) {
cout << "Winsock Start Up Failed!" << endl; // startup winsock
return -1;
}
int mySocket = socket(AF_INET, SOCK_STREAM, 0); // create my socket
if (mySocket == SOCKET_ERROR) {
cout << "Error Opening Socket!" << endl; // make sure nothing bad happened
return -1;
}
struct hostent *host_entry;
if ((host_entry = gethostbyname(serverName)) == NULL) { // setup the host entry
cout << "Could not find host!" << endl;
}
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_port = htons(port); // fill in the server socket info
server.sin_addr.s_addr = *(unsigned long*) host_entry->h_addr;
if (connect(mySocket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) { // connect to the server
cout<< "Error connecting to server!" << endl;
}
cout << "Connection Established" << endl;
return mySocket;
}
o-o'd code, same prob and can't see whats up
ok i have o-o'd part of my code now, but i am still getting the error function cannot take 3 parameters and i can't see whats worng despite fixing it before
Code:
// connecting.cpp: implementation of the connecting class.
//
//////////////////////////////////////////////////////////////////////
#include "connecting.h"
#include <winsock2.h>
#include <stdio.h>
#include <iostream>
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
connecting::connecting()
{
}
connecting::~connecting()
{
}
int connecting::connect(unsigned short port, const char *servername)
{
int error;
WSAData wsaData; // the winsock data structure
if ((error = WSAStartup(MAKEWORD(2, 2), &wsaData)) == SOCKET_ERROR) {
cout << "Winsock Start Up Failed!" << endl; // startup winsock
return -1;
}
int mySocket = socket(AF_INET, SOCK_STREAM, 0); // create my socket
if (mySocket == SOCKET_ERROR) {
cout << "Error Opening Socket!" << endl; // make sure nothing bad happened
return -1;
}
struct hostent *host_entry;
if ((host_entry = gethostbyname(servername)) == NULL) { // setup the host entry
cout << "Could not find host!" << endl;
}
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_port = htons(port); // fill in the server socket info
server.sin_addr.s_addr = *(unsigned long*) host_entry->h_addr;
if (connect(mySocket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) { // connect to the server
cout<< "Error connecting to server!" << endl;
}
cout << "Connection Established" << endl;
return mySocket;
}
void connecting::disconnect(int clientSocket)
{
closesocket(clientSocket); // close socket
WSACleanup(); // shut down winsock
cout <<"Connection Closed" << endl;
}
the header file
Code:
// connecting.h: interface for the connecting class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CONNECTING_H__866BEDBC_0F7C_4EA2_8259_3D5C35DEF3DB__INCLUDED_)
#define AFX_CONNECTING_H__866BEDBC_0F7C_4EA2_8259_3D5C35DEF3DB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class connecting
{
public:
connecting();
virtual ~connecting();
int connect(unsigned short port, const char *serverName);
void disconnect(int clientSocket);
};
#endif // !defined(AFX_CONNECTING_H__866BEDBC_0F7C_4EA2_8259_3D5C35DEF3DB__INCLUDED_)