tags:

views:

132

answers:

6

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?
Thanks.

A: 

You declare both of them :)

Alex Farber
+2  A: 

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.

anon
+5  A: 

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.

Potatoswatter
+1  A: 

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.

Charles Bailey
Yes I did miss typedef.
There is nothing we can do
+1  A: 

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.

James Morris
A: 

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.

McAden