简体   繁体   English

语法说明

[英]Syntax explanation

In code: 在代码中:

struct tagPaint
{
}Paint,//<<<--------------what's this (Paint)?
*pPaint;//<<<-------------and this(*pPaint)?

I mean do I declare variable with name Paint of type tagPaint and pointer called pPaint to tagPaint? 我的意思是要声明名称为Paint的类型为tagPaint的变量以及名为pPaint的指向tagPaint的指针吗?
Thanks. 谢谢。

You are allowed to declare and define a struct or class in a declaration of a variable of that type. 您可以在该类型的变量的声明中声明和定义structclass

So, that declaration defines three symbols: tagPaint (which can also be called struct tagPaint in C style), Paint which is a tagPaint , and pPaint which points to a tagPaint . 因此,该声明定义了三个符号: tagPaint (在C样式中也可以称为struct tagPaint ), Paint其为tagPaint )和pPaint其指向tagPaint

Paint is a variable of type tagPaint. Paint是类型tagPaint的变量。 pPaint is a pointer to type tagPaint. pPaint是类型为tagPaint的指针。 If you want them to define types, then you need: 如果要他们定义类型,则需要:

typedef struct tagPaint {
   ...
}  Paint, * pPaint;

but this is C usage - you should not be writing code like that in C++. 但这是C用法-您不应该使用C ++编写代码。 and even in C, defining a type that hides the fact that something is a pointer is considered bad style. 甚至在C语言中,定义一个隐藏某种东西是指针的事实的类型都被认为是不好的风格。

Yes, in the code that you've actually posted Paint is declared as a struct tagPaint and pPaint is a pointer to a struct tagPaint . 是的,在您实际发布的代码中, Paint被声明为struct tagPaintpPaint是指向struct tagPaint的指针。

Are you sure you haven't missed a typedef from before struct ? 您确定没有从struct之前错过typedef吗? Given the names, defining typedef s would be far more usual. 给定名称后,定义typedef会更加常见。

Paint is an instance of struct tagPaint , and pPaint is a pointer to struct tagPaint . Paintstruct tagPaint的实例,而pPaint是指向struct tagPaint的指针。

The structure needs the typedef keyword preceding it in order to use Paint as a type, and pPaint as a pointer to type Paint . 该结构需要在其前面的typedef关键字才能使用Paint作为类型,而pPaint作为指向Paint类型的指针。

您都声明了它们:)

You're declaring both of them. 您要同时声明两者。 You can declare primitives the same way: 您可以使用以下方式声明基元:

int a, b, c, d;

But instead of the int type you're declaring an instance of tagPaint along with a pointer to a tagPaint. 但是,您不是声明int类型,而是声明了tagPaint的实例以及指向tagPaint的指针。

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

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