C++ sendto() 给出"invalid conversion from ‘int (*)(int, int, int)throw ()’ to ‘int’"错误
C++ sendto() gives "invalid conversion from ‘int (*)(int, int, int)throw ()’ to ‘int’" error
在过去的几周里,我一直在试图解决这个奇怪的问题,但没有成功。
基本上,我正在尝试通过UDP向端点发送消息,并且我正在使用sys/socket.h
下面是给我错误的代码。
sendto(socket, msg.c_str(), msg.size(), 0, (struct sockaddr*) &endpoint,
sizeof(endpoint));
其中endpoint
是sockaddr_in
结构。
编译器抱怨:
错误:从"int (*)(int, int, int)throw ()"到 'int' [-fallowive]
这很有趣,因为该文件是一个组项目,并且代码的其他部分使用与上面完全相同的代码,并且编译器对这些代码感到满意。仅当我将该行复制粘贴到我在同一文件中写入的函数时,它才会给我此错误。
我想不出为什么会发生这种情况。任何想法将不胜感激。
此外,我正在编译-std=c++0x -Wall -pedantic
有一个具有三个int
参数的socket()
函数,
编译器认为您想将其作为第一个参数传递给sendto
。
显然,您在某处也有一个变量socket
,"隐藏"套接字函数,但不在此范围内,因此它采用该功能。停止调用变量socket
,这样会更容易找到(并且在变量已知的部分中调用socket
函数也会更少问题)...
编译器
认为您正在将第一个参数中指向socket
函数的指针传递给sendto
,请尝试更改变量名称。
相关文章:
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- C++错误:"error: int aaa::bbb is protected within this context"
- 错误:从"int"到枚举c++的转换无效
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- 我的 int main() 中出现堆栈溢出错误
- std::cout输出int时出现编译错误
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- 运行时错误:引用绑定到类型为"int"的空指针
- 为什么我会收到"invalid conversion from 'Queue*/Stack*' to 'int'"错误消息?
- 类型"const char[2]"的值不能隐式转换为"int"错误C++
- 如何在<int>错误 C2338 中组织 map<set<multiset>,int> C++
- C++ sendto() 给出"invalid conversion from ‘int (*)(int, int, int)throw ()’ to ‘int’"错误
- 缺少类型说明符-假定为int错误
- 使用int错误进行浮点变量计算
- 数组到数组 -- 将'int*'分配给 'int 错误C++中的不兼容类型
- 为什么我会收到"cannot convert from Dequeu<int> to int"错误?
- int* 转换不允许 int 错误的原因是什么?
- c++将void*强制转换为int错误
- 奇怪的QT无符号Int错误