[solved]Difference between Array and Map of Struct in Struct

Just starting out? Need help? Post your questions and find answers here.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

[solved]Difference between Array and Map of Struct in Struct

Post by Derren »

Hi everybody.

Can somebody enlighten me to the difference between these codes?

I'm putting a Map of structure "myStruct" inside a structure "myStruct" in order to create endless nestable data structures like graphs, for example.
The following code works as expected.

Code: Select all

Structure myStruct
	string.s
	Map test.myStruct() ; 
EndStructure


Define myVar.myStruct
myVar\string = "Hello World"
myVar\test("Test 1")\string = "Hello Test 1"
myVar\test("Test 1")\test("Test 2")\string = "Hello Test 2"

Debug myVar\string
Debug myVar\test("Test 1")\string 
Debug myVar\test("Test 1")\test("Test 2")\string

Now I want to do the same thing with arrays in order to identify a "child-node" by a number instead of a string.

Code: Select all

Structure myStruct
	string.s
	Array test.myStruct(10)
EndStructure
This code won't even compile. Instead I get the following error message.
---------------------------
PureBasic
---------------------------
Line 3: Can't do it, it would cause endless recursivity.
---------------------------
OK
---------------------------
I'm curious.
What is the difference between a Map and an Array that causes the "same" code to function properly and to throw an error like this?
Last edited by Derren on Wed Jan 22, 2020 12:50 pm, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Difference between Array and Map of Structure in Structu

Post by Fred »

A map is initialized with 0 element, so it's not an issue. As the array is initialized with 10 element, every array elemtn will have another array with 10 element and so on. Endless recursivity. List and Map are empty when created, so it stops at the first init.
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Difference between Array and Map of Structure in Structu

Post by Derren »

I see, thank you.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: [solved]Difference between Array and Map of Struct in St

Post by #NULL »

But you can put the array behind a pointer in an allocated structure. You probably know that though :) .
Post Reply