• Lucid Dreaming - Dream Views




    Results 1 to 23 of 23

    Thread: C++ help

    Hybrid View

    1. #1
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Either that,
      or change how you allocate the objects in Body.cpp

      Instead of
      Code:
      Neck = new Object();
      Use
      Code:
      Object Neck();
      (whether you allocate dynamically or not is down to exactly how you're going to be using the objects later on - if they're large, dynamic's always a good idea, as there's limited space on the stack)
      (\_ _/)
      (='.'=)
      (")_(")

    2. #2
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Ooooh. Damn university taught me java, is there ever a more useless language? Is there a good C++ book like 'C in a nutshell'?

      Hey, it compiles!
      Last edited by ninja9578; 05-09-2008 at 01:05 AM.

    3. #3
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Bjarne Stroustrup (the guy who developed C++) has written a few books

      Eg.
      http://www.amazon.co.uk/C%2B%2B-Prog...0291486&sr=8-2
      His stuff tends to be very involved, though

      Any good book store should have loads of C++ books,
      over a wide range of skill levels

      but to be honest, most of the info is online anyway
      check out
      http://www.cprogramming.com/
      and
      http://www.cplusplus.com/
      (\_ _/)
      (='.'=)
      (")_(")

    4. #4
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Quote Originally Posted by ninja9578 View Post
      Hey, it compiles!
      no probs
      (\_ _/)
      (='.'=)
      (")_(")

    5. #5
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      If you've gone the dynamic way, remember to free objects after you've finished with them
      else you'll have a memory leak

      see these for dynamic memory / pointers
      http://www.cprogramming.com/tutorial/lesson6.html
      http://www.cplusplus.com/doc/tutorial/dynamic.html
      Last edited by Ynot; 05-09-2008 at 01:19 AM.
      (\_ _/)
      (='.'=)
      (")_(")

    6. #6
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Oh right, I have to write a destructor. Damn java's garbage collector made me loose everything that I knew about C++.
      Last edited by ninja9578; 05-09-2008 at 03:09 AM.

    7. #7
      The Nihilist MrDoom's Avatar
      Join Date
      Apr 2008
      Gender
      Location
      U$A
      Posts
      187
      Likes
      0
      Remember to make those destructors virtual as well, if you've got an inheritance hierarchy going on anywhere.
      Truths are material, like vegetables and weeds; as to whether vegetable or weed, the decision lies in me.
      --Max Stirner

    8. #8
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Oh crap, I didn't think that through. I have a parent class with some stuff in it, which needs to be purged on calling the destructor, but what happens if I call the destructor for the child class? Will it run both?

      Code:
      class Warrior: public Creature{
      	public:
      		Warrior();
      		~Warrior();
      ...
      The Creature class has dynamically created objects in it too.

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •