object that not Exist

Aug 24, 2012 at 2:38am
hi, how can i use Exception when i send an object, as parameter, when it not exist?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void main()
{
  CLASS1 C1();
  CLASS2 C2();
  CLASS2 C222();
  C1.InsertObject(C2); //ok exist
  C222.~CLASS2(); // call deconstruct 
  C1.InsertObject(C222); //not ok, do not exist -> how to deal with it?
}

class C1
{
   void InsertObject(CLASSE2& c)
   {
      //function code here, but i need use the object
      // if it doesn't exist i'm in trouble 
   }
}


thank you guys
Last edited on Aug 24, 2012 at 3:16am
Aug 24, 2012 at 2:58am
The program simply won't compile.
Aug 24, 2012 at 3:01am
Try to compile that code and see what happens.
Aug 24, 2012 at 3:12am
sorry guys, i did not explain it right.
but if i created object C222 and call it's DESTRUCTOR, but then try to use it again...it will compile and a Windows error say it stopped work.
any suggestion?
Aug 24, 2012 at 3:23am
With great power comes great responsibility.
You're generally not supposed to call destructors manually. The compiler will let you do that, but it will then unload onto you the responsibility not to use the invalid object at all. If you do use it, you're on your own: the language provides no means to check for object validity.

Actually, I think calling a destructor on an automatic object is outright illegal. Can someone confirm this?
Last edited on Aug 24, 2012 at 3:23am
Topic archived. No new replies allowed.