Jump to content

learning C++


Guest thaiko

Recommended Posts

for c++ i would recommend to buy a book, c++ is to big to learn it with tutorials...

in good books (there are good and bad ones) you learn how it works and you'll understand it. not in 5 days, not in 10 days, but maybe in one or two months...

tutorials are good to see how something special works, but not to learn a programming language like c++

Link to comment
Share on other sites

for c++ i would recommend to buy a book, c++ is to big to learn it with tutorials...

in good books (there are good and bad ones) you learn how it works and you'll understand it. not in 5 days, not in 10 days, but maybe in one or two months...

tutorials are good to see how something special works, but not to learn a programming language like c++

Don't suppose you could recommend any good books?

Link to comment
Share on other sites

  • 2 weeks later...
Hello there im also tryng to master c++ is mangos a good way to practice the knoweldge we aquire during the book reading we do or is there a better way to train code developing for starters?

better start with ScriptDev2 , it's a lot easier to understand...at least for me =)

Link to comment
Share on other sites

Hi girls :] ..

I had been programing for a while, before I started understanding mangos.

By the learning of how the mangos or SD2 work I learned lot of things which help me to understand the programing language.

But I got an issue I gotta learn, otherwise I can't do anything at all.

I've never paid attentation to how the Deleting , and Freeing memory work.

I bought a very very huge book year ago, but this one didn't help me in this case.

There weren't any good examples for that. I also tried to look for another one on the internet.

But without any result. So if anyone of you guyz know about some helpful one or about some tutorial or good example

how the delete, free, work, please let me know.

But I need to know how to use this delete in every case.

For example, How to delete an array, or class , structure ...what differences are there between them..

or what conditions I have to keep in case of deleting any element and so on ...

Thanks in advance :]

Cheers!

Link to comment
Share on other sites

  • 2 weeks later...

I've never paid attentation to how the Deleting , and Freeing memory work.

I bought a very very huge book year ago, but this one didn't help me in this case.

There weren't any good examples for that. I also tried to look for another one on the internet.

But without any result. So if anyone of you guyz know about some helpful one or about some tutorial or good example

how the delete, free, work, please let me know.

Cheers!

Pretty much boils down to pairing a delete with every new. Whenever you dynamically allocate memory in your program YOU are responsible for freeing that allocated memory. Otherwise, the memory will always be flagged as in use and if you keeping using new without delete, more and more memory will become unusable.. hence a memory leak. ;)

example: Two classes, Player and Item. Player class contains an Item pointer for its weapon.
class Player
{
public:
 Player() : weapon(new Item) { }  // Default constructor. Create player and make a new weapon

private:
 Item* weapon;
};

So you see here, we have a new Player that has dynamically allocated memory for a weapon. Say we have 500 players online, each object has dynamically allocated memory for their weapons.

Now a player logs off, the player object is gone. But we have a problem, the memory used for the Item is still 'in use' because we never freed that memory. So player will keep logging in and out and in and out tieing up more memory!

We need to fix that with a delete in our destructor.

~Player() { delete item; } // Frees the memory from weapon when player object is destroyed.

Problem solved. ;)

A note for dynamically allocated arrays.. say you have:

// Dynamic array! User creates size.
int n;
std::cout << "Enter an array size: ";
std::cin >> n;
int* x = new int[n]; // Dynamically allocated array of size n.

The syntax for deleting arrays is a little different:

delete [] x; // Brackets are used to delete dynamically allocated arrays.

So just remember, everytime you use the 'new' keyword.. there better be a 'delete' for it somewhere! ;)

Hope this helps.

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use