this is a dynamic struct , this here:
candy *ptr = new candy[3];
should create 3 structs for type candy:
my question here:
1- this creates 3 struct that goes to the heap memory right ?
2- if I used:
candy *ptr[2] = new candy;
this would create two pointers that points to a type candy , right?
3- what I learned is that when you use a dynamic struct , you should access it's variables by using "->" operator , but when I tried to it gives me an error:
type 'candy' does not have an overloaded member 'operator ->'
why ? I know that there's another method to access it's variables but why won't this work ?
* by the way I'm only trying , so this is an example , I know that in every struct there's 3 variables , but I wanted to understand this , so I tried to access a variable at a time
dont make it a pointer. just do candy ptr[3]. if you make it a pointer you need to use the class to pointer operator (->) instead of the direct access dot operator(.)
pointer->blah is a shortcut for (*pointer).blah, so you are always using the dot operator without realizing.
And before someone tries to contradict me, overloading operator-> requires the returned value to also overload operator->, so eventually at the end of the chain it has to be a raw pointer.