#include<iostream>
using namespace std;
typedef char * mychar;
typedef char testchar;
typedef int * myint;
typedef int testint;
void funch(const mychar p){}
void funint(const myint pint){cout<<"for test:"<<*pint<<endl;}
int main()
{
const char *p="hello";
const char ch='a';
const int i=10;
const int *pint=&i;
// fun(p);
//此处error:'fun' : cannot convert parameter 1 from 'const char *' to 'char *const '
funch((mychar)p);
cout<<p<<endl;
cout<<ch<<endl;
cout<<"__________"<<endl;
// fun(pint);
//此处error:'fun' : cannot convert parameter 1 from 'const char *' to 'char *const '
funint((myint)pint);
cout<<*pint<<endl;
cout<<i<<endl;
return 0;
}
输出结果为:
我们在编程的时候往往把char * 看成一个类型,其实不是。上例已经证明,char *往mychar,int *往myint,都是需要强制转换的。