473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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.

Jul 22 '05 #1
2 1921
Digital Puer wrote:
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.

Jul 22 '05 #2
Digital Puer wrote:
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.
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Murat Tasan | last post by:
i am implementing a custom version of the java.util.Map interface. my custom version does some encryption stuff when making modifications to the map via one of the 4 modification methods (put,...
0
by: Martin | last post by:
Hi All, I am a relative newbie to Java / Applets, but am despirately after some help ! I have got the following code, which is basically a listing with button items along the sides, allowing...
2
by: Digital Puer | last post by:
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...
4
by: DaKoadMunky | last post by:
<CODE> #include <iostream> using namespace std; int Foo(int x,int y) { int result = x; result*=y; result+=y;
13
by: interec | last post by:
I have some code in Java that I need to translate into C++. My Java code defines a class hierarchy as follows: // interface IA public interface IA { public abstract void doA(); } //...
4
dmjpro
by: dmjpro | last post by:
plz explain me those two Class and Interface ... give me sample code or good link so that i can learn .... about these things .... and also explain why it is in java ..... thanx in advance...
0
dmjpro
by: dmjpro | last post by:
here is my code .... import java.util.*; class Observer1 implements Observer { public void update(Observable observed,Object o) { System.out.println("Observer1 update method: " + o); }
5
by: koonda | last post by:
Hi all, I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the...
4
by: Mohamed Mansour | last post by:
Hello, What is the purpose of implementing the Observer Pattern if we can trigger an event easily? For example (from books), You have a "Forecaster" which notifies "Observable" when a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.