Sweet pointers....
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]
March 11, 2002 04:43 PM
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.
Kudos to Zumichu for remembering the second way.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement