basic differences from c to c++

Get answers to all your basic programming questions. No Ogre questions, please!
Daepilin
Gnoblar
Posts: 5
Joined: Mon Feb 13, 2012 8:34 pm

basic differences from c to c++

Post by Daepilin »

Hi guys :) i just learned C at university and we won't learn c++ (or java, not even sure, the class is only called object orientated programming) till next winter, but i would still like to start with ogre and OOP. I already did some easy c++ experiments in the past but nothing complicated, i didn't even really get into classes.


But thats it, so is there a good composition of major changes between c and c++, and how to switch? or do i have to start learnign from scratch now?

For the Ogre Tutorials i didn't have huge problems understanding them or the syntax.
User avatar
Waruck
Goblin
Posts: 210
Joined: Mon Dec 12, 2011 12:52 pm
Location: Germany
x 34

Re: basic differences from c to c++

Post by Waruck »

I think the most difficult problem is to get into classes and oop not into the syntax.
An example:
In a game you would perhaps have different characters, lets say humans, elves, dwarfs and orks. But you don't really want your game check what kind of character you're dealing with every time. So what you do is define a base-class 'character' which all the other classes inherit from. Now you could have an character-creation class, that takes an id and creats you an character defined by that specific id. you don't have to care about what race the character is, just treat him like any character. Because it's class is derived from character everybody can see him just as a character, but he acts like its specific race(class).

If you want to get into oop with c++ here are the things I would recommand you:
1. learn about classes and what you can do with them. Learn what inheritance means and what virtual classes are. This is the core of oop.
2. learn about the standard-template-library (stl). Especially about the different containers and how they can be used (vectors, lists, deques, maps...). You'll deal with huge amount of objects and must know how you can store them.
3. learn about design-patterns. These are commonly used patterns how you can use classes in a specific relation to solve specific problems. The pattern in the example above would be a factory-pattern. If you understand these patterns and more importantly why they are useful you'll learn what oop really means.
Baesky
Gnoblar
Posts: 22
Joined: Wed Jun 29, 2011 2:23 am

Re: basic differences from c to c++

Post by Baesky »

Ogre use many OOP Design pattern, which concept more diffcult if u have little exp in c++.
It's hard to say how to learn or study one pragramming language, especially the complex c++. what i can make sure is if u use it as more as possible, u will get it.
In ur situation, i think now to view the ogre code is too early.
any way, keys in ur hand, i just give u a little advise :)
Daepilin
Gnoblar
Posts: 5
Joined: Mon Feb 13, 2012 8:34 pm

Re: basic differences from c to c++

Post by Daepilin »

Waruck wrote:I think the most difficult problem is to get into classes and oop not into the syntax.
An example:
In a game you would perhaps have different characters, lets say humans, elves, dwarfs and orks. But you don't really want your game check what kind of character you're dealing with every time. So what you do is define a base-class 'character' which all the other classes inherit from. Now you could have an character-creation class, that takes an id and creats you an character defined by that specific id. you don't have to care about what race the character is, just treat him like any character. Because it's class is derived from character everybody can see him just as a character, but he acts like its specific race(class).

If you want to get into oop with c++ here are the things I would recommand you:
1. learn about classes and what you can do with them. Learn what inheritance means and what virtual classes are. This is the core of oop.
2. learn about the standard-template-library (stl). Especially about the different containers and how they can be used (vectors, lists, deques, maps...). You'll deal with huge amount of objects and must know how you can store them.
3. learn about design-patterns. These are commonly used patterns how you can use classes in a specific relation to solve specific problems. The pattern in the example above would be a factory-pattern. If you understand these patterns and more importantly why they are useful you'll learn what oop really means.
thx so far, any good recommendations where you would look for information?
User avatar
Waruck
Goblin
Posts: 210
Joined: Mon Dec 12, 2011 12:52 pm
Location: Germany
x 34

Re: basic differences from c to c++

Post by Waruck »

For documantation and sample snipets I usually have a look at http://www.cplusplus.com/
They have some tutorials on classes too, but not very deep.
You can browse the documantation of the stl and read some sample-code but it might be a good idea to look for a real tutorial.
I learnt most stuff in lectures and by working together with more experienced programmers. Writing you own code is the best way to learn.
You can find lots of tutorials about c++, container-classes and design-patterns online. Google is your friend ;) . Or have a look at your University's library, they also shoul have books about c++ and oop. Just make sure to start at a level that fits you.

And write your own code: when learning about containters write a little program that actually fills some containers with random numbers. Maybe have a look at sorting-algorithms and try writing your own sorter. Measure the time it takes to sort different types of container of the same size. And just think of other things you can programm, using the techniques you'll learn and try it.
One of my first tasks when I learned oop was to write a factory method to generate planets with random masses, positions and speeds. I then had to update them and simulate gravitational force between them. One week later I had to add electric charge to the planets and also simulate electrostatic force. This is also a good thing to learn: once you have written some programms try to extend some of them with new features. You'll learn that adding new features isn't always easy and there are things that you can do when writing your original programm, that'll make it easier to add new features.
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56

Re: basic differences from c to c++

Post by Klaim »

I've answered this thread's question before there : http://programmers.stackexchange.com/qu ... en-c-and-c
Daepilin
Gnoblar
Posts: 5
Joined: Mon Feb 13, 2012 8:34 pm

Re: basic differences from c to c++

Post by Daepilin »

thx both of you, and yeah, i already planned on looking at an e-book library ( from the german springer verlag) i can use for free, cause at the moment we've got holidays and getting to university isn't that easy, as most busses between the different campuses don't drive atm.

and my oop lectures come in the next winter term, but i don't really want to wait that long for that^^
User avatar
cybereality
Hobgoblin
Posts: 563
Joined: Wed Jul 12, 2006 5:40 pm
x 12

Re: basic differences from c to c++

Post by cybereality »

Buy this book ( C++ Primer Plus by Stephen Prata ):
http://www.amazon.com/Primer-Plus-5th-S ... 0672326965
iblues1976
Gnome
Posts: 379
Joined: Fri Sep 16, 2011 4:54 pm
x 10

Re: basic differences from c to c++

Post by iblues1976 »

For someone knew at OOP and C++, I personally like the deitel book.

http://www.amazon.com/How-Program-8th-P ... 759&sr=1-1