[program-l] Re: C++ Template Question

  • From: Edward Przybylek <przy5100@xxxxxxxxxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Thu, 29 Sep 2005 22:27:02 -0400

Hi Laura,

Thanks for the explanation. It's actually beginning to make sense. I think the thing that was throwing me is the subscripting of a map element with a string. Do you know if there's any runtime checking to see if a map element has been subscripted with the same string?

Do you know where I might get some accessible documentation on the map and vector libraries? I'm sure I can obtain some documentation in a few days but I have a deadline that doesn't allow for a few days. Possibly something on the MicroSoft site? Thanks an awful lot for all your help.

Take care,
Ed Przybylek <a slightly more educated C++ programmer>

At 04:19 PM 9/29/2005, you wrote:
Hi there -- I can answer this simply (hopefully...).

First of all, C++ declarations of all kinds have declaration syntax that
hints at the syntax required to use the object being declared.
For example, the old C syntax
int* p[10];

indicates that to get down to the int you have to type *p[i], where i is an
int.

Ok, it gets a little nebulous when you get into templates, and the
declaration does not match usage quite the same way.
Now look carefully at what you want to do.  Vector[string> is overloades
operator[] to take an integer subscript and return a string.  So to get the
third element there you need to provide a vector and subascript it with 3.
But how do you get at the vector? The answer is that
Map<string,Vector<string> > mymap; declares a map that overloads operator[]
to take a string subscript and return a vector -- mapping a string to a
vector in other words.
So type

string j3 = mymap["Joe"][3];

to get at the final string.

I know this requires some study of the Vector and Map libraries.  It is not
really a C++ question, but rather a library definition question.

So if you are not sure of a library, go to whatever library documentation
you have.

HTH
--le


----- Original Message ----- From: "Edward Przybylek" <przy5100@xxxxxxxxxxxxxxxx> To: "Program-L" <program-l@xxxxxxxxxxxxx> Sent: Wednesday, September 28, 2005 8:18 PM Subject: [program-l] C++ Template Question


Hi all,

I encountered the following declaration in one of the programs I'm
modifying/enhancing at work:

map<string, vector<string>> mymap;

How does one reference the various elements of this structure.  In
other words, How do I access the fifth or sixth element in the
vector?  I'm sure that to you C++ experts this is obvious but to us
novices (folks like me), it doesn't appear to be that straight
forward.  If you're willing to explain the above, maybe you could
take a crack at the following:

map<string, vector<string, string>> mymap;

The question is the same.  How do I get at the various elements of
the vector in this structure?

What ever happened to the days of assembler, Fortran, Cobol etc. ...
in otherwords, the "good old days"? As always, any help greatly appreciated.

Take care,
Ed Przybylek


** To leave the list, click on the immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe] ** If this link doesn't work then send a message to: ** program-l-request@xxxxxxxxxxxxx ** and in the Subject line type ** unsubscribe ** For other list commands such as vacation mode, click on the ** immediately-following link:- ** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq] ** or send a message, to ** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq


** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: