Advertisement

Sweet pointers....

Started by March 11, 2002 12:27 PM
2 comments, last by LaBasX2 22 years, 11 months ago
Hi! I have got a problem concerning pointers: I have created an array class TArray with an operator[]. So I can access each element of my array simply by writing array = x instead of array.items = x What I want to do now is creating a pointer to this array: TArray* pArray = &array; The problem is that I can't use the [] operator any more directly with the pointer. Thus I can't write pArray = x but I need to write pArray->operator[](i) = x. This is of course very unreadable! Is there any better way? Thanks in advance LaBasX2
(*pArray) = x;<br><br>the pointer to your array class is just and integer. There is no information of member functions untill you dereference it. You could create a class to abstract your pointer that also implements an operator[] (just a wrapper around your current operator) but that may be defeating your purpose. <br><br>I did absolutely nothing, and it was everything that I thought it could be!
[I did absolutely nothing, and it was everything that I thought it could be]
Advertisement
There are two ways to access the members of a pointer to a struct. The first is with the -> operator and the second is to derefernce it just like you would any other pointer. The second way is not commonly used or even thought of.

Kudos to Zumichu for remembering the second way.
Thanks a lot for your replies! They have really helped me!

LaBasX2

This topic is closed to new replies.

Advertisement