map as member variable of a class

Discussion in 'C++' started by wang, Jul 22, 2010.

  1. wang

    wang Guest

    Hi all,
    I have the class declaration as follows:

    class MyClass {
    public:
    map<string, string> account;
    }

    The main program uses the class as follows:

    MyClass customer;
    string acc = "abc", ort = "xyz";
    customer.account[acc] = ort;

    In VC++6, the compilation succeeded, but debug causes the error when
    running the last instruction ("customer.account[acc] = ort;"):

    Unhandled exception in customer.exe (MSVCRTD.DLL): 0xC0000005: Access
    Violation.

    What should be done to avoid this? Many thanks in advance!

    kwwang
    wang, Jul 22, 2010
    #1
    1. Advertising

  2. wang

    haroon Guest

    On Jul 22, 4:55 pm, wang <> wrote:

    > What should be done to avoid this? Many thanks in advance!
    >


    Upgrade to a newer compiler / stop living in the past...
    haroon, Jul 22, 2010
    #2
    1. Advertising

  3. wang

    wang Guest

    On 23 Jul., 01:29, Christian Hackl <> wrote:

    > There is nothing wrong with your code. If you really need VC6 to get it
    > right then you should probably ask in a Microsoft newsgroup.


    Thank you, Christian! I've written a simple console test program,
    which runs really well. In my program which throws the exception, the
    class is defined in a .DLL. In the console test program, all are in
    one file. Maybe this is the reason.
    kwwang
    wang, Jul 24, 2010
    #3
  4. wang

    wang Guest

    On 24 Jul., 02:23, Stuart Golodetz
    <> wrote:
    > I seem to remember encountering this problem in the past. Here are a few
    > relevant links to things which look like it:
    >
    > http://support.microsoft.com/kb/172396

    http://support.microsoft.com/kb/168958/
    http://stackoverflow.com/questions/2451714/access-violation-when-acce...
    http://stackoverflow.com/questions/1085873/dll-memory-manager-mixup
    >
    > Off the top of my head, try using the multithreaded DLL versions of the
    > runtime library for both your .dll and your .exe.


    Thank you, Stuart! On the page of the first link you indicated above,
    I found already a solution: accessor method instead of direct
    subscipting.

    Now another question: besides accessing the container via a key (which
    can
    be easily realized by accessor method), I'd like
    to iterate through the whole container, and the container might be
    very
    complicated, i.e. a component of the container is itself a container,
    e.g. nested container as map< string, map< string, vector
    <class_object> > > .
    How can such operation (iteration) be realized by means of an accessor
    method?

    kwwang
    wang, Jul 27, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,716
    Thomas Weidenfeller
    Oct 12, 2005
  2. slide_o_mix
    Replies:
    0
    Views:
    410
    slide_o_mix
    Oct 15, 2003
  3. Alex
    Replies:
    0
    Views:
    380
  4. Siemel Naran
    Replies:
    4
    Views:
    789
    Micah Cowan
    Jan 12, 2005
  5. Peng Yu
    Replies:
    3
    Views:
    1,068
    Simon Forman
    Sep 21, 2009
Loading...

Share This Page