Ok I need your help

This is a discussion on Ok I need your help within the C++ Programming forums, part of the General Programming Boards category; /* Consider the following............*/ [code] // Listing 13.7 - An array on the free store #include <iostream> class CAT { ...

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Ok I need your help

    /* Consider the following............*/
    [code]
    // Listing 13.7 - An array on the free store

    #include <iostream>

    class CAT
    {
    public:
    CAT() { itsAge = 1; itsWeight=5; }
    ~CAT();
    int GetAge() const { return itsAge; }
    int GetWeight() const { return itsWeight; }
    void SetAge(int age) { itsAge = age; }

    private:
    int itsAge;
    int itsWeight;
    };

    CAT :: ~CAT()
    {
    // cout << "Destructor called!\n";
    }

    int main()
    {
    CAT * Family = new CAT[500];
    int i;

    for (i = 0; i < 500; i++)
    {
    Family[i].SetAge(2*i +1);
    }

    for (i = 0; i < 500; i++)
    {
    std::cout << "Cat #" << i+1 << ": ";
    std::cout << Family[i].GetAge() << std::endl;
    }

    delete [] Family;
    int exit; cin>>exit;
    return 0;
    }

    /* Which is place here on the stack and which is placed on free store in terms of the array and the object */
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    once again thank you I think I got it though.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

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