Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Starting with SFML - coming form a java world!  (Read 2069 times)

0 Members and 1 Guest are viewing this topic.

Eric

  • Newbie
  • *
  • Posts: 4
    • View Profile
Starting with SFML - coming form a java world!
« on: May 05, 2013, 09:34:14 am »
Congratulations with the release of 2.0! I just managed to get the old 2.0 installed on my Xcode a week ago :-) I  find it very interesting

I'm an experienced java-programmer and I've heard a lot about memory leaks, pointers and other warnings about c++ in the past - but I really like SFML and want to try it out

I have a question regarding the C++ language. I know there is no garbage collector in c++, but should I worry about destroying objects / smart pointers and stuff in C++? I'm new to c++ but syntax seems very familiar and I want to learn that language.

Eric

Dragnalith

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Starting with SFML - coming form a java world!
« Reply #1 on: May 05, 2013, 11:15:36 am »
Yes, in C++ you have to worry about destroying objects if they have been created dynamically (it means "with the new operator"). New thing in C++ which doesn't exist in Java is the destructor method of a class. It lets you define what to do when your object is destroyed ("how to destroy attributes").

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Starting with SFML - coming form a java world!
« Reply #2 on: May 05, 2013, 11:30:55 am »
The most important thing when you come from Java, is to forget about new the way you were used to. The new operator is not the default way to create an object in C++ -- it is used for dynamic memory management, and requires a delete to destroy an object. In modern C++, you should rarely use new, and if you do, you directly encapsulate it into a smart pointer. This principle is called RAII, a crucial C++ idiom you should definitely have an in-depth look at.

Generally, don't think that because you know Java, it will be easy to learn C++. The language is fundamentally different, even if there are similarities on the first impression. The whole programming paradigm differs from Java, C++ uses less pure OOP and focuses on other abstraction techniques such as templates. There are also a lot of language features that are completely new, like global functions, operator overloading, const qualifiers, lambda expressions, pointers and references, typedef, ...

To sum up, if you really want to learn C++, read a good book. You won't learn the language from internet tutorials, most of them teach questionable and deprecated style. If you have a book, you can still skip basic language features like loops that are the same as in Java -- but already classes you should re-learn, because there are some important differences. Here is a list of good C++ books.  Be aware that it will take a lot of time to learn C++. Even if you know Java, C++ is far more complex and contains a lot of pitfalls and special rules you have to know in order to program efficiently. If it's just for SFML, you might also consider the JSFML binding for Java.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Eric

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Starting with SFML - coming form a java world!
« Reply #3 on: May 06, 2013, 10:01:02 am »
I've ordered som c++ books and while I wait I follow this 'course': http://www.learncpp.com

I strongly recommend this page if other wants to learn c++ without a book!

 

anything