-1

I've encountered this in Visual C++ applications

extern map<string, rpcfn_type> mapCallTable;

or

 map<string, string>

What does it mean? Not the map thing, but the

<string, string> 

part

Magnus Hoff
  • 21,529
  • 9
  • 63
  • 82
dikidera
  • 2,004
  • 6
  • 29
  • 36
  • Well it's hard to see those parts separately. See http://www.cplusplus.com/reference/stl/map/ or perhaps better http://www.uow.edu.au/~nabg/ABC/ABC.html – sehe May 04 '11 at 20:27
  • They're the template parameters, it's mapping a string to a string, or a string to an rpcfn_type in the first example – forsvarir May 04 '11 at 20:27
  • Before you write any more Visual C++ applications, you may want to [read a good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Robᵩ May 04 '11 at 20:30
  • 2
    I never said i was writing, i said i've encountered this in Visual C++ – dikidera May 04 '11 at 20:31

3 Answers3

10

Those are template parameters; map is a class template, and it's not complete until you tell it the types it will be working with. The first is the type of the key, and the second is the type of the data that will be stored via the key.

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
1

std::map is a template. You use it to create a type that has a key and some data associated with that key. The angle brackets is where you specify those two types, so (for example), map<string, string> is defining a type that uses one string as the key, and has another string associated with the first one.

One that's perhaps easier to follow would something like:

struct person {        
    string name;
    string email_address;
    phone_number home;
    phone_number mobile;
};

map<string, person> people;

This let's me (for example) use a nickname as the key to look up the name, email address, phone numbers, etc. for a person.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
0

You can't take the <string, string> part separately because it's a modifier to map.

map is a template type, and <string, string> refers to the types it uses. map<string, string> means a map whose key type is string and whose value type is also string.

Mark B
  • 95,107
  • 10
  • 109
  • 188