Thread: array of objects

  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,793
    Threads have been merged

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07: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, 11:26 AM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. Adding objects to an array
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 11-27-2001, 09:24 AM