|
From: Daniel K. O. <dan...@ya...> - 2004-08-24 02:20:11
|
Noorez Kassam wrote:
> extern "C"
> {
>
> struct anything
> {
> int a;
> int b;
> };
>
> }
>
> but since this is a c struct then why could i create an object of the
> type like this anything a;
> C doesn't allow this.
Don't think of it as an object."anything" is a C struct, not a class. So
you use like a C struct. This line will fail to compile:
---
anything a;
---
because there's no type "anything". But there IS a type "struct
anything", so you can use:
---
struct anything a;
---
to create a variable of this type ("struct anything"). If you don't want
to write "struct anything", you have to declare your struct like this:
---
typedef struct
{
int a;
int b;
}anything;
---
Now you can just write "anything a;", as "anything" is now a new type.
My recomendation: try not to mix C and C++ when you are learning one of
them; learn them as independent languages (if you learned C++ first,
don't skip the C introduction, or you will only get confused about the
details; the same applies to learning C first and then C++).
Daniel K. O.
|