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

Author Topic: Help *lol*  (Read 8868 times)

0 Members and 1 Guest are viewing this topic.

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Help *lol*
« Reply #15 on: September 25, 2008, 10:38:23 pm »
Quote from: "ravenheart"
as far as i know

new and delete are for dynamic memory;

im sorry bur i dont have any clue how i should use it in my class

when i create a bat

bat x;;
do i need to add some code concerning destruction?

and when i creat it by pointer?

bat *x = new bat;
do i have do add something like

~bat(){ x = NULL);  ?


Whenever you use new, you have to use delete at some point to free that memory.  And yes, that's for dynamic memory allocated at run time (what you're calling "create by pointer.")  If you just declare variables without new, you don't need to call delete.

MrQuizzles

  • Newbie
  • *
  • Posts: 15
    • View Profile
Help *lol*
« Reply #16 on: September 26, 2008, 06:40:41 am »
Quote from: "ravenheart"
bat *x = new bat;
do i have do add something like

~bat(){ x = NULL);  ?


It'd simply be

Code: [Select]
delete x;

and yes, any anonymous variables you have floating around need to be specifically deleted in the destructor. If you don't, then they'll be doomed to sit in memory until the application ends since you'll no longer have any way to reference them.


Also be very sure that you don't try to use that pointer after it's been deleted. This can happen when you pass that location around a bit. You'll get a fun, fun null pointer exception and wonder where and why it is happening.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Help *lol*
« Reply #17 on: September 26, 2008, 07:45:52 am »
Don't inherit from sf::Shape. A bat is not a shape, it's implemented using a shape, which means composition or private inheritance.
Laurent Gomila - SFML developer

 

anything