template struct question

Steven Schveighoffer schveiguy at gmail.com
Thu Feb 13 22:32:07 UTC 2025


On Wednesday, 12 February 2025 at 20:55:14 UTC, WhatMeWorry wrote:
> ```d
> void main()
> {
>
> struct HexBoard(F,I)
> {
>     this(F d, I r, I c) {}
>     //void displayHexBoard(HexBoard!(F,I) h) {}  // this 
> compiles fine!
> }
>
> void displayHexBoard(HexBoard!(F,I) h) {}  // error undefined 
> identifier F and I
>
>
> auto h1 = HexBoard!(float,uint)(.25, 3, 7);
> auto h2 = HexBoard!(double,int)(.3, 5, 5);
>
> }
> ```
>
> Is there any clever way to move the method outside of a 
> templated block structure?  Or is this as good as it gets.
>

The problem is that the compiler doesn't know what F and I are. 
They are placeholders, but you didn't give them a definition.

```d
void displayHexBoard(F, I)(HexBoard!(F,I) h) {}
```

-Steve


More information about the Digitalmars-d-learn mailing list