CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85

    Problem with object scope...?

    I was given a project that has DialogClassA, DialogClassB, and DataClass1 and they're setup like this. DialogClassA's ctor uses "new" to instantiates an obj of DialogClassB (even though it's not visible yet), and DialogClassB's ctor instantiates an obj of DataClass1 via "new" too. ( DataClass1 holds the data object for the dialog from DialogClassB).

    The user hits a button on DialogClassA to bring up a Dialog of type DialogClassB and manipulate & save data and exit.

    Problem: the DataClass1 obj is not destroyed when DialogClassB closes and remains around until DialogClassA's dctor kills DialogClassB and DialogClassB's dctor calls DataClass1's dctor. When the user re-opens the DialogClassB it still has the old data in it from the last time the user had it opened. Should I:

    1) only create a DataClass1 object when the user Opens up the DialogClassB and does a File->New or File->Open, then destroy it when DialogB closes? (haven't gotten this to work yet)

    2)...ah, something else.

    It's seems terribly inefficient to have an object of DataClass1 hang around until the entire application closes just because of the way the "new"s and "delete"s were set up by someone in the ctors & dctors. I don't have a ton of experience in this but what do you think?

    Thanks.....

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    It designs on the design. What is the significance of DataClass1? Is it a temporary object or does it actually store essential data that the program needs?

    Kuphryn

  3. #3
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    85
    Originally posted by kuphryn
    It designs on the design. What is the significance of DataClass1? Is it a temporary object or does it actually store essential data that the program needs?

    Kuphryn
    It's not really temporary... it's a propriatary data object that holds std::lists of std::lists and the DialogClass2 is just the user interface for it. Once the user saves the data from DialogClass2 to a DataClass1 object file it seems it could go away.

  4. #4
    Join Date
    Feb 2002
    Posts
    5,757
    There are many other factors that come into play such as how much data DataClass1 display? How often does the user accesses DataClass1?

    Analyze all factors and decide for yourself.

    Kuphryn

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured