Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > map as member variable of a class

Thread Tools

map as member variable of a class

Posts: n/a
Hi all,
I have the class declaration as follows:

class MyClass {
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

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


Reply With Quote
Posts: n/a
On Jul 22, 4:55*pm, wang <(E-Mail Removed)> wrote:

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

Upgrade to a newer compiler / stop living in the past...
Reply With Quote
Posts: n/a
On 23 Jul., 01:29, Christian Hackl <(E-Mail Removed)> 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.
Reply With Quote
Posts: n/a
On 24 Jul., 02:23, Stuart Golodetz
<(E-Mail Removed)> wrote:
> I seem to remember encountering this problem in the past. Here are a few
> relevant links to things which look like it:
> 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

Now another question: besides accessing the container via a key (which
be easily realized by accessor method), I'd like
to iterate through the whole container, and the container might be
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


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
parse error in gcc but success in, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
Can Derived class static member access protected member from base class? Siemel Naran C++ 4 01-12-2005 06:46 PM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM