doing C++ the Java way

C

Carmen Sei

I need to write a C++ application prototype that uses a graphics
engine in 2 weeks.

http://openframeworks.cc/about

I know Java pretty well, but I don't know C++.

Can i write the C++ prototype using only Java equivalent features?

I only use Class objects, static variable, single inheritance
(extends), new+free()/delete(), #define

C++ features that I don't use - no struct, no enum, no extern, no
non-OO, no multiple inheritance, no template ... etc

I think if I do that way, I will be able to finish my C++ prototype
quickly, all I need to do is translate the Java program (.java) file
into .cpp and .h file.

Is it a good idea for a person need to finish a C++ app (about 8 - 10
cpp files) in 2 weeks and don' t know C++?

the app need to call some Class / Library from the graphics framework
above and do some internet XML parsing and render data into cool
graphics ... etc.
 
D

dave_mikesell

Can i write the C++ prototype using only Java equivalent features?

I only use Class objects, static variable, single inheritance
(extends), new+free()/delete(), #define

First, don't use free with new, use delete. And what is the Java
equivalent of #define?
Is it a good idea for a person need to finish a C++ app (about 8 - 10
cpp files) in 2 weeks and don' t know C++?

Good? Sounds like a typical management decision. You can probably
kludge something that does what you want, but make sure you burn the
prototype and learn C++ before they ask you to flesh it out to a
product.
 
G

Greg Herlihy

First, don't use free with new, use delete.

To be more "Java-like" I would not use delete either, but instead rely
on shared_ptr's to manage allocated pointers.

  And what is the Java
equivalent of #define?

Pretty much the same as it is in C++. In both C++ and Java, a (non-
macro) #define would be replaced by a const variable declaration -
while a #define that creates a preprocessor macro would be rewritten
as a - in the C++ case, an inline - function.

Well, I guess in two weeks you will know the answer to that question.

Greg
 
J

James Kanze

I need to write a C++ application prototype that uses a graphics
engine in 2 weeks.

I know Java pretty well, but I don't know C++.

In which case, you can't write a reasonable application
prototype in C++ in two weeks. It's that simple.
Can i write the C++ prototype using only Java equivalent
features?

There are fundamental differences in the language---it's not
just a matter of feature sets, but differences in the way the
languages work.
I only use Class objects, static variable, single inheritance
(extends), new+free()/delete(), #define
C++ features that I don't use - no struct, no enum, no extern,
no non-OO, no multiple inheritance, no template ... etc

No extern? You mean you write everything in a single source
file?
I think if I do that way, I will be able to finish my C++
prototype quickly, all I need to do is translate the Java
program (.java) file into .cpp and .h file.

You can find a common subset of features, and only use them.
You may even be able to get something through the compiler doing
this. It won't have the same semantics, however.
Is it a good idea for a person need to finish a C++ app (about
8 - 10 cpp files) in 2 weeks and don' t know C++?

If you don't know C++, I don't think you'll be able to get
anything reasonably working in 2 weeks. If you're talking about
8-10 source files, it depends on what you put in the source
file. I know that there are a lot of applications which would
only be 8-10 classes that I couldn't do in two weeks, and I
already know the language.
the app need to call some Class / Library from the graphics
framework above and do some internet XML parsing and render
data into cool graphics ... etc.

If it's only a prototype... You're best bet (although it's still
a long shot) would be to learn enough C++ to write a Java
mapping in JNS, and write the actual prototype in Java. C++ is
not a simple tool which can be learned in a few days.
 
J

James Kanze

On Mar 7, 7:55 pm, (e-mail address removed) wrote:
To be more "Java-like" I would not use delete either, but
instead rely on shared_ptr's to manage allocated pointers.

shared_ptr aren't very Java-like. To be more Java-like, he
could install a garbage collector. But C++ with garbage
collection isn't really very Java-like either (and you do need
someone who really knows what they're doing to configure the
garbage collector for your environment).

In his case, since it's a prototype, the simplest solution is
probably just to use raw pointers, call delete when it's obvious
when delete needs to be called, and let the application leak a
bit.
And what is the Java
Pretty much the same as it is in C++. In both C++ and Java, a
(non- macro) #define would be replaced by a const variable
declaration - while a #define that creates a preprocessor
macro would be rewritten as a - in the C++ case, an inline -
function.

And a #define which plays games with program structure doesn't
have an equivalent in Java. Going from Java to C++, he can
pretty much ignore #define to begin with, except for include
guards.
 
J

Juha Nieminen

Carmen said:
I need to write a C++ application prototype that uses a graphics
engine in 2 weeks.

http://openframeworks.cc/about

I know Java pretty well, but I don't know C++.

Can i write the C++ prototype using only Java equivalent features?

Coding in C++ in the same way as you would code in Java is usually a
bad idea. Even though they remotely resemble each other, C++ is not
Java, and the coding principles are totally different. If you try to
code in C++ as if you were coding in Java, you will get memory leaks
with almost 100% certainty (yeah, bummer, but it just is like that) and
the code will most probably be less efficient (both speedwise and
memorywise) than doing it in the "C++ way".
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top