pointer!

Here is my sample code, i want ptr to get updated when i'm modifying it after accessing through member function.Please correct if i'm doing wrong, let me know if there is better solution.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class object{
public:
int length;
char* ptr;

char* & getPtr() { return this->ptr }
};

int main() {
  object dummy;
  char* dataPointer;
  dataPointer = dummy.getPointer(); // will this refer to ptr
  dataPointer++; // will this increment ptr of dummy.
  return 0;
}
Yes, because you have the actual object not just a copy of it. I was actually experimenting with this recently and found this site:

http://markgodwin.blogspot.ca/2009/08/c-reference-to-pointer.html
wow... cool stuff.. thanks Smac :-)
Topic archived. No new replies allowed.