开发者

Syntax explanation

In code:

struct tagPaint
{
}Paint,//<<<--------------what's this (Paint)?
*pPaint;//<<<-------------and this(*pPa开发者_JS百科int)?

I mean do I declare variable with name Paint of type tagPaint and pointer called pPaint to tagPaint?

Thanks.


You are allowed to declare and define a struct or class in a declaration of a variable of that type.

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.


Paint is a variable of type tagPaint. pPaint is a pointer to type 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++. and even in C, defining a type that hides the fact that something is a pointer is considered bad style.


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.

Are you sure you haven't missed a typedef from before struct? Given the names, defining typedefs would be far more usual.


Paint is an instance of struct tagPaint, and pPaint is a pointer to 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.


You declare both of them :)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜