简体   繁体   English

函数式转换语法如何工作?

[英]How does function-style cast syntax work?

I guess I am a bit puzzled by the syntax. 我想我对语法有点困惑。 What does the following mean? 以下是什么意思?

typedef char *PChar;
hopeItWorks = PChar( 0x00ff0000 );

It is equivalent to (PChar) 0x00ff0000 or (char *) 0x00ff0000 . 它相当于(PChar) 0x00ff0000(char *) 0x00ff0000 Syntactically think of it as invoking a one-argument constructor. 在语法上将其视为调用单参数构造函数。

SomeType(args) means explicit constructor call if SomeType is user-defined type and usual c-cast (SomeType)args if SomeType is fundamental type or a pointer. 如果SomeType是用户定义的类型,则SomeType(args)表示显式构造函数调用,如果SomeType是基本类型或指针,则通常使用c-cast (SomeType)args

PChar is equivalent to char * (pointer). PChar相当于char * (指针)。 Thus hopeItWorks = (char *)0x00ff0000; 因此hopeItWorks = (char *)0x00ff0000;

typedef char *PChar;

Its typedef of char* to Pchar . 它的char*Pchar typedef。 Instead of using char* you can define variables with Pchar. 您可以使用Pchar定义变量,而不是使用char*

hopeItWorks = PChar( 0x00ff0000 );

Its equivalent to ==> 它相当于==>

 hopeItWorks = (char *)( 0x00ff0000 );

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

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