简体   繁体   中英

what is void* in the explicit cast operator and what is use of it?

I just came across below code in mscorlib IntPtr structure while pressing F12 in visual studio.

public static unsafe explicit operator void* (IntPtr value)
{
    return value.m_value;
}

I do know that we can define explicit cast operator like this but it is void* so I am confused what is this and what is use of that?

Void* is a void pointer. It is a construct that is often used in C++. Most of the times it is used when you want to use a pointer for either a multiple other data types or if you are not sure what datatype you will use the pointer for.

In essence you can see it as sort of a generic as it can be cast to any other pointer type and vice versa. It is usually used when dealing with unmanaged code and is a C++ construct. In managed code it normally finds no usage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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