Home Cannot create class in AHK after destruction
Reply: 0

Cannot create class in AHK after destruction

user1016
1#
user1016 Published in April 26, 2018, 7:44 am

I'm trying to wrap my head around classes in AHK. I'm C++ dev, so would like to make use of RAII (__New, __Delete), but it looks like I miss some concepts since things look very contra-intuitive for me.

After some tries I came up with this simple example:

class Scenario
{
  __New()
  {
    MsgBox, NEW
  }

  __Delete()
  {
    MsgBox, DELETE
  }
}

scenario := new Scenario
scenario := new Scenario
scenario := 1
scenario := {}
scenario := new Scenario
Return

As a result I get the following messages:

  1. NEW
  2. NEW
  3. DELETE
  4. DELETE

Questions:

  1. Why doesn't the object get destroyed during the second assignment? I'd assume the number of refs going to 0, no?
  2. How come I get 2 destructions in a row? Where was that object stored meanwhile? How could scenario variable hold both references?
  3. Why was not the third construction called?
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.343959 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO