accessing pointers question

Started by
12 comments, last by MARS_999 21 years, 2 months ago
First off, what your trying to do is dangerous. The initialization of the class objects creates the pointer variable, but the pointer variable itself doesn't store a valid memory address. It probably has some strange value, unless you set it explicitly in the constructor. If you try to assign a value to the memory the un-initialized pointer points to, then that's bad.

What you can do in your constructor is allocate memory for that pointer, and in the destructor release that memory. That way, you can use the pointer safely.

And the proper syntax is *(foo[0].fp) = 1.3f;. If that doesn't work, then something else might be wrong. Give us the compile/link error if that's what you are getting.

EDIT: Bah, you beat me

quote:Ok I got this syntax to work finally. But why *(stuff) for a syntax.

It makes the code look clearer.

quote:THis works also.

Yeah, operator precedence makes it work out.



[edited by - Zipster on January 30, 2003 7:24:28 PM]
Advertisement
quote:Original post by MARS_999
But why *(stuff) for ab syntax.
Duh. Obviously to make it clear what is being dereferenced.

edit: Bah, Zipster's edit beat me

[edited by - civguy on January 30, 2003 7:30:33 PM]
So the procedure would be to allocate new memory with new on the foo[] and then loop through the foo[] and use new to allocate memory to the fp pointer. I think I got it!! And then when you delete the memory you need to delete the foo[].fp first with a loop and then delete the foo[] right? Thanks
just one litle question, doesn''t he have to do: ?
foo[0].fp = new float
humanity will always be slaved by its ignorance

This topic is closed to new replies.

Advertisement