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 21:24:06 UTC 2024
    
    
  
On Thu, Jun 27, 2024 at 08:56:13PM +0000, WhatMeWorry` via Digitalmars-d-learn wrote:
> import std.container : RedBlackTree;
> 
> int main()
> {
> 
>     struct Location {
>         int x;
>         int y;
>     }
> 
>     struct Node{
>         this(Location loc, uint f) {
>             this.loc = loc;
>             this.f = f;
>         }
>         Location loc;
>         uint f;
>     }
> 
> auto priorityQueue = new RedBlackTree!(Node, "a.f < b.f", true); // true:
> allowDuplicates
> 
> // C:\D\dmd2\windows\bin64\..\..\src\phobos\std\container\rbtree.d(806):
> Error: `main` is
> // a nested function and cannot be accessed from
> // `std.container.rbtree.RedBlackTree!(Node, "a.f < b.f",
> true).RedBlackTree.allocate`
> 
> return 0;
> }
Move the declaration of Location and Node outside of main and it should
work.
T
-- 
Almost all proofs have bugs, but almost all theorems are true. -- Paul Pedersen
    
    
More information about the Digitalmars-d-learn
mailing list