简体   繁体   English

C ++编译错误c2664 ZeroMemory

[英]C++ compile error c2664 ZeroMemory

Why does this ZeroMemory(&socketAddress, sizeof(Connection::socketAddress)); 为什么这个ZeroMemory(&socketAddress, sizeof(Connection::socketAddress)); work, but this doesn't? 工作,但这不?

ZeroMemory(&Connection::socketAddress, sizeof(Connection::socketAddress));

I get this error: error C2664: 'memset' : cannot convert parameter 1 from 'sockaddr_in Connection::* ' to 'void *' 我收到此错误: error C2664: 'memset' : cannot convert parameter 1 from 'sockaddr_in Connection::* ' to 'void *'

&Connection::socketAddress is a member pointer. &Connection::socketAddress是一个成员指针。 It's not itself a pointer, but a way to get a pointer to a particular member of a class given a pointer to that class. 它本身不是一个指针,而是一种在给定指向该类的指针的情况下获取指向类的特定成员的指针的方法。 ZeroMemory can't accept it because it doesn't actually point to any real memory; ZeroMemory无法接受它,因为它实际上并没有指向任何真实的内存; it needs more information (a pointer to the instance of the class containing the member) before it can actually get a real pointer. 它需要更多信息(指向包含该成员的类的实例的指针)才能真正获得真正的指针。

Take a look at this question for more information about member pointers. 有关成员指针的更多信息,请查看此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM