objects

This is a discussion on objects within the C++ Programming forums, part of the General Programming Boards category; Something I am very confused about..assuming I had the class and functions found below. When the printTestData() fnct starts running, ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    94

    objects

    Something I am very confused about..assuming I had the class and functions found below.

    When the printTestData() fnct starts running, will the listObj contain anything in it? or am I suppose to first return and the send the listObj via pass by reference to the printTestData() fnct?

    Also...if I am suppose to send the listObj via pass by reference, then why am I declaring it within the class structure? Couldn't I just create it in the createTestList() function and then send it?

    Code:
    class Test
    {
        private:
           SLList<Dictionary> listObj;
           Dictionary dObj;
           createTestList ();
           printTestData();
          .....
          .....
    };
    
    //--------------------------------------------------
    void Test::createTestList()
    {
        ....
        while (i++ < something)
        {
            ....
            ....
            listObj.makeLink(dObj);
        }
    }
    //---------------------------------------------------
    void Test::printTestData()
    {
       ....
       ....
       while (i++ < something)
       {
             dObj = listObj.printList();  <--Here
             cout << dObj.data << endl;
        }
    }
    //---------------------------------------------------
    int main ()
    {
         Test x;
         x. createTestList();
         x.printTestData();
         return 0;
    }
    thanx
    simple is always an understatement.....

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    There's too little source code to say.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    This code is for sample purposes....normally if in a condition where a list, tree etc is created using a obj declared within the class, would the contents within that object cease to exist when the function using it has finnished with it? That is what I am after. I know it would not exist if the obj was declared within the function.
    simple is always an understatement.....

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,668
    All your member variables of an instance will persist as long as the instance itself persists.

    In other words, while "x" is valid, all members of "x" are valid.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. most efficient way to write filestream objects?
    By darsunt in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2009, 04:17 PM
  2. Replies: 60
    Last Post: 12-20-2005, 10:36 PM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM

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