转换LPVOID IN CHAR ERROR C2440:=

时间:2016-05-12 21:15:42

标签: c++ visual-studio memory memory-management

如何将LPVOID转换为char?

char * pCacheMap;

pCacheMap = MapViewOfFile(hCacheMapping,FILE_MAP_READ|FILE_MAP_WRITE,0,0,0);

错误:

    3   IntelliSense: a value of type "LPVOID" cannot be assigned to an entity of type "char *" 
Error   1   error C2440: '=' : cannot convert from 'LPVOID' to 'char *' 

1 个答案:

答案 0 :(得分:1)

使用演员。由于LPVOID是void *的同义词,因此将其强制转换为任何其他指针类型是合法的:

pCacheMap = static_cast<char *>(MapViewOfFile(...)); 

会奏效。