套接字绑定函数编译错误

Compilation errors with socket bind function

本文关键字:错误 编译 函数 绑定 套接字      更新时间:2023-10-16

一开始,我包含了以下文件,绑定函数

一切正常
#include "stdafx.h"
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

绑定功能

iResult = bind(ListenSocket, result->ai_addr, (int)result->ai_addrlen);

当我包含mysql库时,事情开始变得混乱

#include "stdafx.h"
#undef UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
//mysql connections
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

我开始调试,它给了我这个错误

IntelliSense: no suitable conversion function from "std::_Bind<false, void, SOCKET &, sockaddr *&, int>" to "int" exists    
error C2440: '=' : cannot convert from 'std::_Bind<false,void,SOCKET &,sockaddr *&,int>' to 'int'

请帮。

我猜问题不包括Mysql库,我得到了这个问题一次,我修复了它删除

using namespace std;

或者另一种解决方案是从全局命名空间调用bind来避免此类问题;

我忘了写从全局命名空间调用bind是这样做的:

::bind(...);