• Lucid Dreaming - Dream Views




    Results 1 to 23 of 23

    Thread: C++ help

    Hybrid View

    1. #1
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935

      C++ help

      Been a long long time since I've written anything in C++, I'm getting back into it. I need a little help, because I don't understand the errors Here's the error and the setup of the groups. I have other files that try and create the same type of objects and they don't give me errors.


    2. #2
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Can you post the contents of Body.h
      (\_ _/)
      (='.'=)
      (")_(")

    3. #3
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Bien Sur

      Code:
      #ifndef BODY_H
      #define BODY_H
      
      #include "Object.h"
      #include "Limb.h"
      
      class Body{
          public:
              Body();  // parameterless default constructor
      	private:
      		Object torso;
      		Object neck;
      		Object head;
      		Limb leftarm;
      		Limb rightarm;
      		Limb leftleg;
      		Limb rightleg;
      };
      
      #endif
      Hmm, don't know why the indents came out like that

    4. #4
      FBI agent Ynot's Avatar
      Join Date
      Oct 2005
      Gender
      Location
      Southend, Essex
      Posts
      4,337
      Likes
      14
      Ok,
      You're allocating the objects dynamically (using new)
      so the members in Body.h need to be pointers
      (new returns a pointer to the object on the heap)

      Code:
          private:
              Object* torso;
              Object* neck;
              Object* head;
              Limb* leftarm;
              Limb* rightarm;
              Limb* leftleg;
              Limb* rightleg;
      (\_ _/)
      (='.'=)
      (")_(")

    5. #5
      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)
      (\_ _/)
      (='.'=)
      (")_(")

    6. #6
      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.

    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
    •