Thread: how to de-reference a pointer to a map

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    10

    how to de-reference a pointer to a map

    Hi

    If I have a pointer to a map container:

    Code:
    map<int, double>* mapPointer = &aMap;
    how do I then de-reference the pointer to access a member through its key?

    Code:
    double a = map[4]; // works
    double b = mapPointer*[4]; // incorrect - how do I do this?
    thanks

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Same way you would do any other object, put the * in front:
    Code:
    double c = (*mapPointer)[4];
    >> double a = map[4]; // works
    BTW, that should be "compiles", not "works", since it of course does not actually work.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    10
    many thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Textbox
    By maxorator in forum Windows Programming
    Replies: 20
    Last Post: 09-25-2005, 10:04 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. STL MAP Question
    By deadpoet in forum C++ Programming
    Replies: 11
    Last Post: 02-24-2004, 06:37 AM