Resetting a class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JohnSmith70
    New Member
    • Oct 2007
    • 22

    Resetting a class

    Lets say I have a class, which creates object and variables. In main how do I reset that class to null, as if it was (the class run for the first time) first run, but without exitting the main?
  • JohnSmith70
    New Member
    • Oct 2007
    • 22

    #2
    Originally posted by JohnSmith70
    Lets say I have a class, which creates object and variables. In main how do I reset that class to null, as if it was (the class run for the first time) first run, but without exitting the main?
    I ve noticed that when I write an if statement, because I only want it it reset "if asked for a reset". It doesn't work. But without the if statement it works. Why is that? How do make it work? I want to make the declaration inside the if block to be global. How do I do that?

    Comment

    • JonLT
      New Member
      • Jul 2007
      • 41

      #3
      if you declare anything inside an if block the variable will run out of scope i.e end to exist when you are nolonger inside the if block, you need to put the declaration outside the if block

      Comment

      • JohnSmith70
        New Member
        • Oct 2007
        • 22

        #4
        Originally posted by JonLT
        if you declare anything inside an if block the variable will run out of scope i.e end to exist when you are nolonger inside the if block, you need to put the declaration outside the if block
        if I put it outside the block, it would reset it even if I don't want it to.

        Comment

        • JonLT
          New Member
          • Jul 2007
          • 41

          #5
          how about this (I don't know how you code looks)
          Code:
          SomeClass MyClass;
          MyClass.someIntMember = 5;
          if(wantToReset)
          do the resetting

          Comment

          • Parul Bagadia
            New Member
            • Mar 2008
            • 188

            #6
            You can declare all its objects and variables to null; what about this?

            Comment

            • whodgson
              Contributor
              • Jan 2007
              • 542

              #7
              If the class has at least a constructor and a destructor there should be no need for resetting - just call the required member function again and it should behave as for the first run.

              Comment

              Working...