PDA

View Full Version : pointer base problem



mickey
7th November 2007, 20:00
create (vector<ClassA>* vec) {
cout << " vec " << vec << endl;
cout << " &vec " << &vec << endl;
cout << " &vec[0] " << &vec[0] << endl;
cout << " (&vec)[0] " << (&vec)[0] << endl;

Hi, I cant understand why 1 and 3 print the same address: 1 should be print the content of vec (that's the address to which vec point ie the address of vector that create take; 2 sould be the address of variabile vec; 3 for me shouldn't exists: [ and ] have precedence on & ???

DeepDiver
7th November 2007, 20:09
vec is a pointer to a vector.
Streaming it will give you the address.

Note: class vector has no stream operators defined - you can not stream the content of vector this way.
You can define this stream operator yourself if you want.

mickey
7th November 2007, 21:36
create (vector<ClassA>* vec) {
cout << " vec " << vec << endl;
cout << " &vec " << &vec << endl;
cout << " &vec[0] " << &vec[0] << endl;
cout << " (&vec)[0] " << (&vec)[0] << endl;

Hi, I cant understand why 2 and 4 print the same address: 2 should print the content of vec (that's the address to which vec point ie the address of vector that create take; 3 should be the address of variabile vec; 4 for me shouldn't exists: [ and ] have precedence on & ???
Sorry I did a mistake in numeration, so I have corrected it.....