GNOME Bugzilla – Bug 622440
destructors for structs
Last modified: 2018-05-22 13:39:23 UTC
Is there a fundamental reason why structs can have constructors but not destructors? I knows structs are stack based, but a destructor may still be necessary if we manually allocate memory in them. For example when I try to compile the following test struct Test { int* pointer; Test() { pointer = new int[10]; } ~Test() { stdout.printf("Destroying!\n"); delete pointer; } } void main() { var p = Test(); } I get an error message: error: unexpected declaration in struct ~Test() ^^^^^^^ Compilation failed: 1 error(s), 0 warning(s)
True that this causes a memory leak. If pointer is defined like below the destructor is correctly declared. struct Test { int[] pointer; Test() { pointer = new int[10]; } } void main() { var p = Test(); }
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/111.