implementing Java's Observable in C/C++?

D

Digital Puer

I have to convert some existing Java code into C/C++. One of the
Java classes implements Observable. Can someone suggest how
I might write this in C/C++? I'm thinking I would need something
like function pointers, but I've never used those... Thanks for
any help.
 
P

Peter Ashford

Digital said:
I have to convert some existing Java code into C/C++. One of the
Java classes implements Observable. Can someone suggest how
I might write this in C/C++? I'm thinking I would need something
like function pointers, but I've never used those... Thanks for
any help.

Why would you need function pointers?

Interfaces and base classes can be translated into C++ fairly directly.
Use std::vector to hold your observables and iterate through them when
doing notification.

I don't see where your issue is - I'd do this in C++ in almost exactly
the same way I'd do it in Java (this is a design pattern, not a language
issue)

Peter.
 
S

Steven T. Hatton

Digital said:
I have to convert some existing Java code into C/C++. One of the
Java classes implements Observable. Can someone suggest how
I might write this in C/C++? I'm thinking I would need something
like function pointers, but I've never used those... Thanks for
any help.

Do you know how to implement the event/listener pairs in Java from scratch?
Do the same with C++. If you aren't threading, then you don't need to
worry about /synchronized/ methods. Use javap on the commandline to get a
clear view of the class's interface.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top