Results 1 to 3 of 3

Thread: pointer base problem

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default pointer base problem

    Qt Code:
    1. create (vector<ClassA>* vec) {
    2. cout << " vec " << vec << endl;
    3. cout << " &vec " << &vec << endl;
    4. cout << " &vec[0] " << &vec[0] << endl;
    5. cout << " (&vec)[0] " << (&vec)[0] << endl;
    To copy to clipboard, switch view to plain text mode 
    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 & ???
    Regards

  2. #2
    Join Date
    Oct 2007
    Location
    Munich, Bavaria
    Posts
    144
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pointer base problem

    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.

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: pointer base problem

    Qt Code:
    1. create (vector<ClassA>* vec) {
    2. cout << " vec " << vec << endl;
    3. cout << " &vec " << &vec << endl;
    4. cout << " &vec[0] " << &vec[0] << endl;
    5. cout << " (&vec)[0] " << (&vec)[0] << endl;
    To copy to clipboard, switch view to plain text mode 
    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.....
    Regards

Similar Threads

  1. Connecting to a base class signal?
    By AaronMK in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 22:37
  2. QTable - Data Base Problem
    By esq in forum Qt Tools
    Replies: 9
    Last Post: 27th May 2007, 23:08
  3. QTable - Date Base Problem
    By esq in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2007, 02:32
  4. Signals destroys my pointer
    By Jojo in forum Qt Programming
    Replies: 12
    Last Post: 7th March 2006, 21:05
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.