By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,661 Members | 791 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,661 IT Pros & Developers. It's quick & easy.

Structs and pointers

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.