digitalmars.D.learn - Implementing a tree with recursive Algebraic
- Kamil Koczurek (14/14) Jun 15 2018 Hi,
- Adam D. Ruppe (5/6) Jun 15 2018 A tree there would be storing a copy of a tree which is storing a
- Kamil Koczurek (3/5) Jun 15 2018 Oh, alright. I changed Tree to be a class instead of a struct and
Hi,
I'm trying to implement a simple tree and this 3-liner was my
initial idea:
struct Tree(T) {
Algebraic!(Tree, T)[] content;
}
But it doesn't work and I get the following error message:
/.../variant.d(...): Error: struct `app.Tree` no size because of
forward reference
/.../variant.d(...): Error: template instance
`std.variant.maxSize!(Tree, string)` error instantiating
source/app.d(10,3): instantiated from here:
`Algebraic!(Tree, string)`
Can I somehow fix this, or is my approach inherently flawed?
Jun 15 2018
On Friday, 15 June 2018 at 14:53:13 UTC, Kamil Koczurek wrote:Can I somehow fix this, or is my approach inherently flawed?A tree there would be storing a copy of a tree which is storing a copy of a tree... where would it end? You can make the tree store a *pointer* to a tree though. That's the traditional way to do it and it works here too.
Jun 15 2018
On Friday, 15 June 2018 at 14:57:33 UTC, Adam D. Ruppe wrote:You can make the tree store a *pointer* to a tree though. That's the traditional way to do it and it works here too.Oh, alright. I changed Tree to be a class instead of a struct and it seems to work just fine now. Thanks a lot!
Jun 15 2018








Kamil Koczurek <koczurekk gmail.com>