12 line program... `main` is a nested function when trying to use redblacktree. Beginner error???

H. S. Teoh hsteoh at qfbox.info
Thu Jun 27 22:18:09 UTC 2024


On Thu, Jun 27, 2024 at 10:14:06PM +0000, WhatMeWorry via Digitalmars-d-learn wrote:
> Thanks, that did the trick. Not sure why having the declarations at
> global scope (or is it module scope in D) would work versus having
> them at local scope?

If you stuck 'static' to the local scope declarations that ought to fix
it too.  The main problem is that without 'static', there will be a
hidden context pointer in the struct that points to the main's local
scope. This can't work with RBTree because it cannot obtain a pointer to
this local scope when it needs to create new nodes.


T

-- 
Freedom: (n.) Man's self-given right to be enslaved by his own depravity.


More information about the Digitalmars-d-learn mailing list