先看看在C语言中, test.c如下:
- int main()
- {
- int *p;
- char *q;
- void *v;
-
- v = p;
- q = v;
-
- return 0;
- }
程序ok, 但程序的风格本身就不好, 而且不便于移植到C++
在C++语言中, test.cpp如下:
- int main()
- {
- int *p;
- char *q;
- void *v;
-
- v = p;
- q = v;
-
- return 0;
- }
编译出错:error C2440: '=' : cannot convert from 'void *' to 'char *' Conversion from 'void*' to pointer to non-'void' requires an explicit cast. C++更严格, 更好。