开发者

Is it possible to create a pointer of type object instead of type class or structure?

Sorry if this question is poorly worded (please edit it if it will make it easier for readers to understand me.)

I'm new to oop and was learning some C code. What does this last line of code mean? Is there a way to paradigmatically(I just made up this word) write it differently?

typedef struct _Song {
//some members
} Song;

Song * pSong=0;
开发者_开发问答

Shouldn't it be:

_Song * pSong=0;

Instead of:

Song * pSong=0;

...since Song is an object and _Song is a structure.


Song is nothing more than an alias for struct _Song (that's what the typedef at the beginning means). There is absolutely no difference between the two, wrt their type.

In C++, the syntactic difference is even more marginal, since _Song is also an alias for struct _Song.


A typedef creates an alias for a type. You can write them inline with struct definitions to get short names for a struct. E.g.

typedef int** int_dbl_ptr;

Normally, if you defined _Song without a typedef, you'd have to write struct _Song*, but with the typedef it's just Song*.

You can also create structs inline with variable declarations, e.g.

struct foo {int bar; int baz; } a, b, c;

creates a struct of type struct foo and declares three struct foos, a, b, and c.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜