HELP!!! - new to visual c++

Sharky Forums


Results 1 to 4 of 4

Thread: HELP!!! - new to visual c++

  1. #1
    Goldfish
    Join Date
    Jul 2001
    Location
    England
    Posts
    67

    Question HELP!!! - new to visual c++

    can anyone help me please,

    i have to create classes (which i understand) and these have to be stored as anonymous objects in an array. my problem is that i do not know how to package different defined class objects together as identical array objects (if that makes sense).

    more specifically my array has to hold 10 objects and these objects can be trees, sheds etc (for a garden design), i am totally lost as im a new programmer so any help would be greatly appreciated.

    cheers.

    p.s. does anyone know of any sites which may be of help with either explainations or examples of related coding.

  2. #2
    Goldfish DarkAvenger's Avatar
    Join Date
    Dec 2001
    Location
    India --> Australia
    Posts
    72
    From what I understand of your question you want a list of classes, garden, shed, tools, etc. placed in arrays of index 10, is that right?

    Is this the kind of stuff you've tried?

    class Garden
    {
    ...
    };

    Garden garden [10];

    class Shed
    {
    ...
    };

    Shed shed [10];

    or maybe

    class Gardening
    {
    Garden garden;
    Shed shed;
    ...
    };

    Gardening gardenContainer[10];

    I hope I was on the right track.

  3. #3
    Catfish arcane_III's Avatar
    Join Date
    Apr 2002
    Location
    East Coast, USA
    Posts
    151
    Sounds to me like you need to use inheritance.

    you will basically design a base class, such as
    class GardenObjects
    { ... }

    then derive other classes from this base class
    class Shed : GardenObjects
    (or using java decl: class Shed extends GardenObjects )

    so if you shed's, tree's, flower's, etc. all derive from the base class then you can use this declaration to store different types of GardenObjects.

    GardenObjects gardenArr[];

    and you can store all your objects in the array using code like this:
    Shed myShed;
    Tree myTree;
    gardenArr[0] = myShed;
    gardenArr[1] = myTree;

    etc...

    That should get the job done.
    If you have learned about pointers you may want to use an array of pointers instead of just an array of GardenObjects.

    Hope that helps some.

    This is basically psyeudocode I may not have the declarations (or the syntax) exactly correct because I have not programmed C++ in quite a while. And this code may be polluted with Java syntax.
    Last edited by arcane_III; 04-11-2002 at 03:03 PM.

  4. #4
    Sleeps with the Fishes oSpIkEo's Avatar
    Join Date
    Nov 2001
    Location
    glendale,ca,USA
    Posts
    189
    Dude, why dont you start From C then go to c++
    since c is ez

Posting Permissions

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