array of objects

This is a discussion on array of objects within the C++ Programming forums, part of the General Programming Boards category; class Base{ public: int x; int y; }; class...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    13

    array of objects

    class Base{
    public:
    int x;
    int y;
    };

    class

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Code tags? Proper grammar?

    Code:
    class base {
    public:
       int x, y, z;
       double whocares;
    } my_array[200];
    //creates an array of too bases
    
    /*******
         OR
    *******/
    
    class base {
    public:
       int x, y, z;
       double whocares;
    };
    
    base my_array[200];
    
    /*******
         OR
    *******/
    
    class base {
    public:
       int x, y, z;
       double whocares;
    };
    
    typedef base array[200];
    
    array my_array;

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    13

    array of objects

    class BASE{
    public:
    int x;
    int y;
    int c;
    void print(void){cout<<"base";}
    };

    class CHILD1 : public BASE{
    void print(void){cout<<"child1";}
    };

    class CHILD2 : public BASE{
    void print(void){cout<<"child2";}
    }

    How to make array
    that CHILD1 and CHILD2 both objects are in it?

    int main(int argc, char* argv[]){
    BASE * base[2];
    base[0]=new CHILD1;
    base[1]=new CHILD2;

    base[0].print();
    base[1].print();

    return 0;
    }

    it gives

    base base

    but I want

    child1 child2



    how to make it work?

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    13
    sry
    I pushed the button too early

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Threads have been merged

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. Replies: 4
    Last Post: 10-16-2003, 12:26 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM
  5. Adding objects to an array
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 11-27-2001, 09:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21