Advertisement
Guest User

for alexbuisson

a guest
Jul 13th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. main.h
  2. =================
  3. #include <iostream>
  4. #include <map>
  5.  
  6. enum
  7. {
  8.     weapon,
  9.     ammo,
  10.     food
  11. };
  12.  
  13. class c_items
  14. {
  15.     bool operator()(const c_items& l, const c_items& r) const
  16.     {
  17.         return (l.id < r.id);
  18.     }
  19. public:
  20.     c_items(void){};
  21.     c_items(int id, char name[], int type, double weight);
  22.     char *name;
  23.     int type;
  24.     double weight;
  25.     int id;
  26. };
  27.  
  28. extern std::map<int,c_items> Stuff;
  29.  
  30. c_items::c_items(int id, char name[], int type, double weight) : id(id), type(type), name(name), weight(weight)
  31. {
  32.     Stuff[id] = *this;
  33. }
  34.  
  35. extern c_items
  36.     brass_knuckles,
  37.     golf_club;
  38. =================
  39. main.cpp
  40. =================
  41. #include "main.h"
  42.  
  43. std::map<int,c_items> Stuff;
  44.  
  45. c_items
  46.     brass_knuckles          (1, "Brass knuckles", weapon, 0.1),
  47.     golf_club               (2, "Gold club", weapon, 0.8);
  48.  
  49. using namespace std;
  50.  
  51. int main()
  52. {
  53.     cout << Stuff[1].name << endl;
  54.     cout << golf_club.name;
  55.     return 1;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement