470,832 Members | 2,079 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,832 developers. It's quick & easy.

Structs and pointers

Hi,

i know, it would be very stupid question, but i'm c-beginner and i haven't
found the answer in books. Ok, here it is.

I have:
typedef struct {
cdContext contextH;
/* stream I/O function pointers */
cdSOpen* open;
cdSClose* close;
cdSRead* read;
cdSWrite* write;
cdSSeek* seek;
cdSTell* tell;
} cdStream;

If i declare MyStream:
cdStream MyStream;
... how can i use its properties, that are pointers?

So: (*MyStream).open .. ?
Or maybe so: MyStream->open?
or so: *(MyStream.open)?
or so:MyStream.(*open)?
Or all of them are wrong?

Thanx.

Apr 20 '06 #1
3 1483
Timur Ametov wrote:
Hi,

i know, it would be very stupid question, but i'm c-beginner and i haven't
found the answer in books.


You're probably looking for our neighbours, comp.lang.c because C and
C++
are different languages.
The code that you included is C code, and while C++ understands it,
it's
not how you'd write these things in C++ at all.

Do check the C Faq, though, it's good.

Michiel.

Apr 20 '06 #2
Timur Ametov Đ´µŔ:
Hi,

i know, it would be very stupid question, but i'm c-beginner and i haven't
found the answer in books. Ok, here it is.

I have:
typedef struct {
cdContext contextH;
/* stream I/O function pointers */
cdSOpen* open;
cdSClose* close;
cdSRead* read;
cdSWrite* write;
cdSSeek* seek;
cdSTell* tell;
} cdStream;

If i declare MyStream:
cdStream MyStream;
.. how can i use its properties, that are pointers?

So: (*MyStream).open .. ?
Or maybe so: MyStream->open?
or so: *(MyStream.open)?
or so:MyStream.(*open)?
Or all of them are wrong?

Thanx.

My point of view , the usage is as below:
(Mystream.open)()
Mystream is a object of the struct.
open is one of its variable.
Apr 20 '06 #3
The way to use it dependce on the object you have:
If you defined cdStream as pointer the way to use its properties is:
cdStream->open
If cdStream is not a pointer the way to use its properties is:
cdStream.open

because open is a function to a pointer you should use it exactly like
it was a function:
cdStream->open(), or
cdStream.open().

Regards

Apr 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Christian F | last post: by
5 posts views Thread by Bilgehan.Balban | last post: by
15 posts views Thread by Paminu | last post: by
12 posts views Thread by barcaroller | last post: by
17 posts views Thread by Johan Tibell | last post: by
5 posts views Thread by dev_15 | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.